@ -9,6 +9,7 @@
# include <common/amount.h>
# include <common/amount.h>
# include <common/bech32.h>
# include <common/bech32.h>
# include <common/bolt11.h>
# include <common/bolt11.h>
# include <common/configdir.h>
# include <common/features.h>
# include <common/features.h>
# include <common/json_command.h>
# include <common/json_command.h>
# include <common/json_helpers.h>
# include <common/json_helpers.h>
@ -161,10 +162,12 @@ static void invoice_payload_remove_set(struct htlc_set *set,
payload - > set = NULL ;
payload - > set = NULL ;
}
}
static bool hook_gives_failcode ( const char * buffer ,
static bool hook_gives_failcode ( struct log * log ,
const char * buffer ,
const jsmntok_t * toks ,
const jsmntok_t * toks ,
enum onion_type * failcode )
enum onion_type * failcode )
{
{
const jsmntok_t * resulttok ;
const jsmntok_t * t ;
const jsmntok_t * t ;
unsigned int val ;
unsigned int val ;
@ -172,9 +175,39 @@ static bool hook_gives_failcode(const char *buffer,
if ( ! buffer )
if ( ! buffer )
return false ;
return false ;
resulttok = json_get_member ( buffer , toks , " result " ) ;
if ( resulttok ) {
if ( json_tok_streq ( buffer , resulttok , " continue " ) ) {
return false ;
} else if ( json_tok_streq ( buffer , resulttok , " reject " ) ) {
* failcode = WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS ;
return true ;
} else
fatal ( " Invalid invoice_payment hook result: %.*s " ,
toks [ 0 ] . end - toks [ 0 ] . start , buffer ) ;
}
t = json_get_member ( buffer , toks , " failure_code " ) ;
t = json_get_member ( buffer , toks , " failure_code " ) ;
if ( ! t )
# ifdef COMPAT_V080
if ( ! t & & deprecated_apis ) {
static bool warned = false ;
if ( ! warned ) {
warned = true ;
log_unusual ( log ,
" Plugin did not return object with "
" 'result' or 'failure_code' fields. "
" This is now deprecated and you should "
" return {'result': 'continue' } or "
" {'result': 'reject'} or "
" {'failure_code': 42} instead. " ) ;
}
return false ;
return false ;
}
# endif /* defined(COMPAT_V080) */
if ( ! t )
fatal ( " Invalid invoice_payment_hook response, expecting "
" 'result' or 'failure_code' field: %.*s " ,
toks [ 0 ] . end - toks [ 0 ] . start , buffer ) ;
if ( ! json_to_number ( buffer , t , & val ) )
if ( ! json_to_number ( buffer , t , & val ) )
fatal ( " Invalid invoice_payment_hook failure_code: %.*s " ,
fatal ( " Invalid invoice_payment_hook failure_code: %.*s " ,
@ -222,7 +255,7 @@ invoice_payment_hook_cb(struct invoice_payment_hook_payload *payload,
}
}
/* Did we have a hook result? */
/* Did we have a hook result? */
if ( hook_gives_failcode ( buffer , toks , & failcode ) ) {
if ( hook_gives_failcode ( ld - > log , buffer , toks , & failcode ) ) {
htlc_set_fail ( payload - > set , failcode ) ;
htlc_set_fail ( payload - > set , failcode ) ;
return ;
return ;
}
}