@ -142,10 +142,14 @@ json_add_routefail_info(struct json_stream *js,
}
}
void json_sendpay_fail_fields ( struct json_stream * js ,
void json_sendpay_fail_fields ( struct json_stream * js ,
const struct wallet_payment * payment ,
int pay_errcode ,
int pay_errcode ,
const u8 * onionreply ,
const u8 * onionreply ,
const struct routing_failure * fail )
const struct routing_failure * fail )
{
{
/* "immediate_routing_failure" is before payment creation. */
if ( payment )
json_add_payment_fields ( js , payment ) ;
if ( pay_errcode = = PAY_UNPARSEABLE_ONION )
if ( pay_errcode = = PAY_UNPARSEABLE_ONION )
json_add_hex_talarr ( js , " onionreply " , onionreply ) ;
json_add_hex_talarr ( js , " onionreply " , onionreply ) ;
else
else
@ -161,6 +165,7 @@ void json_sendpay_fail_fields(struct json_stream *js,
/* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */
/* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */
static struct command_result *
static struct command_result *
sendpay_fail ( struct command * cmd ,
sendpay_fail ( struct command * cmd ,
const struct wallet_payment * payment ,
int pay_errcode ,
int pay_errcode ,
const u8 * onionreply ,
const u8 * onionreply ,
const struct routing_failure * fail ,
const struct routing_failure * fail ,
@ -181,6 +186,7 @@ sendpay_fail(struct command *cmd,
data = json_stream_fail ( cmd , pay_errcode ,
data = json_stream_fail ( cmd , pay_errcode ,
errmsg ) ;
errmsg ) ;
json_sendpay_fail_fields ( data ,
json_sendpay_fail_fields ( data ,
payment ,
pay_errcode ,
pay_errcode ,
onionreply ,
onionreply ,
fail ) ;
fail ) ;
@ -202,6 +208,7 @@ json_sendpay_in_progress(struct command *cmd,
static void tell_waiters_failed ( struct lightningd * ld ,
static void tell_waiters_failed ( struct lightningd * ld ,
const struct sha256 * payment_hash ,
const struct sha256 * payment_hash ,
const struct wallet_payment * payment ,
int pay_errcode ,
int pay_errcode ,
const u8 * onionreply ,
const u8 * onionreply ,
const struct routing_failure * fail ,
const struct routing_failure * fail ,
@ -215,7 +222,8 @@ static void tell_waiters_failed(struct lightningd *ld,
if ( ! sha256_eq ( payment_hash , & pc - > payment_hash ) )
if ( ! sha256_eq ( payment_hash , & pc - > payment_hash ) )
continue ;
continue ;
sendpay_fail ( pc - > cmd , pay_errcode , onionreply , fail , details ) ;
sendpay_fail ( pc - > cmd , payment ,
pay_errcode , onionreply , fail , details ) ;
}
}
}
}
@ -510,8 +518,8 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
failmsg ,
failmsg ,
fail ? fail - > channel_dir : 0 ) ;
fail ? fail - > channel_dir : 0 ) ;
tell_waiters_failed ( ld , & hout - > payment_hash , pay_errcode ,
tell_waiters_failed ( ld , & hout - > payment_hash , payment ,
hout - > failuremsg , fail , failmsg ) ;
pay_errcode , hout - > failuremsg , fail , failmsg ) ;
}
}
/* Wait for a payment. If cmd is deleted, then json_waitsendpay_on_resolve
/* Wait for a payment. If cmd is deleted, then json_waitsendpay_on_resolve
@ -567,7 +575,9 @@ static struct command_result *wait_payment(struct lightningd *ld,
" Payment failure reason unknown " ) ;
" Payment failure reason unknown " ) ;
} else if ( failonionreply ) {
} else if ( failonionreply ) {
/* failed to parse returned onion error */
/* failed to parse returned onion error */
return sendpay_fail ( cmd , PAY_UNPARSEABLE_ONION ,
return sendpay_fail ( cmd ,
payment ,
PAY_UNPARSEABLE_ONION ,
failonionreply ,
failonionreply ,
NULL , faildetail ) ;
NULL , faildetail ) ;
} else {
} else {
@ -583,6 +593,7 @@ static struct command_result *wait_payment(struct lightningd *ld,
/* FIXME: We don't store this! */
/* FIXME: We don't store this! */
fail - > msg = NULL ;
fail - > msg = NULL ;
return sendpay_fail ( cmd ,
return sendpay_fail ( cmd ,
payment ,
faildestperm
faildestperm
? PAY_DESTINATION_PERM_FAIL
? PAY_DESTINATION_PERM_FAIL
: PAY_TRY_OTHER_ROUTE ,
: PAY_TRY_OTHER_ROUTE ,
@ -721,8 +732,8 @@ send_payment(struct lightningd *ld,
& route [ 0 ] . channel_id ,
& route [ 0 ] . channel_id ,
& channel - > peer - > id ) ;
& channel - > peer - > id ) ;
return sendpay_fail ( cmd , PAY_TRY_OTHER_ROUTE , NULL ,
return sendpay_fail ( cmd , payment , PAY_TRY_OTHER_ROUTE ,
fail , " First peer not ready " ) ;
NULL , fail , " First peer not ready " ) ;
}
}
/* Copy channels used along the route. */
/* Copy channels used along the route. */