@ -162,10 +162,11 @@ static void invoice_payload_remove_set(struct htlc_set *set,
payload - > set = NULL ;
}
static bool hook_gives_failcode ( struct log * log ,
const char * buffer ,
const jsmntok_t * toks ,
enum onion_type * failcode )
static const u8 * hook_gives_failmsg ( const tal_t * ctx ,
struct log * log ,
const struct htlc_in * hin ,
const char * buffer ,
const jsmntok_t * toks )
{
const jsmntok_t * resulttok ;
const jsmntok_t * t ;
@ -173,15 +174,14 @@ static bool hook_gives_failcode(struct log *log,
/* No plugin registered on hook at all? */
if ( ! buffer )
return false ;
return NULL ;
resulttok = json_get_member ( buffer , toks , " result " ) ;
if ( resulttok ) {
if ( json_tok_streq ( buffer , resulttok , " continue " ) ) {
return false ;
return NULL ;
} else if ( json_tok_streq ( buffer , resulttok , " reject " ) ) {
* failcode = WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS ;
return true ;
return failmsg_incorrect_or_unknown ( ctx , hin ) ;
} else
fatal ( " Invalid invoice_payment hook result: %.*s " ,
toks [ 0 ] . end - toks [ 0 ] . start , buffer ) ;
@ -213,13 +213,16 @@ static bool hook_gives_failcode(struct log *log,
fatal ( " Invalid invoice_payment_hook failure_code: %.*s " ,
toks [ 0 ] . end - toks [ 1 ] . start , buffer ) ;
/* UPDATE isn't valid for final nodes to return, and I think
* we assert elsewhere that we don ' t do this ! */
if ( val & UPDATE )
fatal ( " Invalid invoice_payment_hook UPDATE failure_code: %.*s " ,
toks [ 0 ] . end - toks [ 1 ] . start , buffer ) ;
* failcode = val ;
return true ;
/* FIXME: Allow hook to return its own failmsg directly? */
if ( val = = WIRE_TEMPORARY_NODE_FAILURE )
return towire_temporary_node_failure ( ctx ) ;
if ( val ! = WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS )
log_broken ( hin - > key . channel - > log ,
" invoice_payment hook returned failcode %u, "
" changing to incorrect_or_unknown_payment_details " ,
val ) ;
return failmsg_incorrect_or_unknown ( ctx , hin ) ;
}
static void
@ -229,7 +232,7 @@ invoice_payment_hook_cb(struct invoice_payment_hook_payload *payload,
{
struct lightningd * ld = payload - > ld ;
struct invoice invoice ;
enum onion_type failcode ;
const u8 * failmsg ;
/* We notify here to benefit from the payload and because the hook callback is
* called even if the hook is not registered . */
@ -249,14 +252,16 @@ invoice_payment_hook_cb(struct invoice_payment_hook_payload *payload,
/* If invoice gets paid meanwhile (plugin responds out-of-order?) then
* we can also fail */
if ( ! wallet_invoice_find_by_label ( ld - > wallet , & invoice , payload - > label ) ) {
failcode = WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS ;
htlc_set_fail ( payload - > set , failcode ) ;
htlc_set_fail ( payload - > set , take ( failmsg_incorrect_or_unknown (
NULL , payload - > set - > htlcs [ 0 ] ) ) ) ;
return ;
}
/* Did we have a hook result? */
if ( hook_gives_failcode ( ld - > log , buffer , toks , & failcode ) ) {
htlc_set_fail ( payload - > set , failcode ) ;
failmsg = hook_gives_failmsg ( NULL , ld - > log ,
payload - > set - > htlcs [ 0 ] , buffer , toks ) ;
if ( failmsg ) {
htlc_set_fail ( payload - > set , take ( failmsg ) ) ;
return ;
}