mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
API: Add payment fields(if not NULL) into return value when sendpay fails
pPayment field includes the basic information of the payment, so the return valves of 'sendpay_success()' and 'sendpay_fail()' should include this field. Note "immediate_routing_failure" is before payment creation, and for this case, return won't include payment fields.
This commit is contained in:
parent
507f8d46df
commit
9d8f46149a
@ -142,10 +142,14 @@ json_add_routefail_info(struct json_stream *js,
|
||||
}
|
||||
|
||||
void json_sendpay_fail_fields(struct json_stream *js,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
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)
|
||||
json_add_hex_talarr(js, "onionreply", onionreply);
|
||||
else
|
||||
@ -161,6 +165,7 @@ void json_sendpay_fail_fields(struct json_stream *js,
|
||||
/* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */
|
||||
static struct command_result *
|
||||
sendpay_fail(struct command *cmd,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct routing_failure *fail,
|
||||
@ -181,6 +186,7 @@ sendpay_fail(struct command *cmd,
|
||||
data = json_stream_fail(cmd, pay_errcode,
|
||||
errmsg);
|
||||
json_sendpay_fail_fields(data,
|
||||
payment,
|
||||
pay_errcode,
|
||||
onionreply,
|
||||
fail);
|
||||
@ -202,6 +208,7 @@ json_sendpay_in_progress(struct command *cmd,
|
||||
|
||||
static void tell_waiters_failed(struct lightningd *ld,
|
||||
const struct sha256 *payment_hash,
|
||||
const struct wallet_payment *payment,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
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))
|
||||
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,
|
||||
fail ? fail->channel_dir : 0);
|
||||
|
||||
tell_waiters_failed(ld, &hout->payment_hash, pay_errcode,
|
||||
hout->failuremsg, fail, failmsg);
|
||||
tell_waiters_failed(ld, &hout->payment_hash, payment,
|
||||
pay_errcode, hout->failuremsg, fail, failmsg);
|
||||
}
|
||||
|
||||
/* 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");
|
||||
} else if (failonionreply) {
|
||||
/* failed to parse returned onion error */
|
||||
return sendpay_fail(cmd, PAY_UNPARSEABLE_ONION,
|
||||
return sendpay_fail(cmd,
|
||||
payment,
|
||||
PAY_UNPARSEABLE_ONION,
|
||||
failonionreply,
|
||||
NULL, faildetail);
|
||||
} else {
|
||||
@ -583,6 +593,7 @@ static struct command_result *wait_payment(struct lightningd *ld,
|
||||
/* FIXME: We don't store this! */
|
||||
fail->msg = NULL;
|
||||
return sendpay_fail(cmd,
|
||||
payment,
|
||||
faildestperm
|
||||
? PAY_DESTINATION_PERM_FAIL
|
||||
: PAY_TRY_OTHER_ROUTE,
|
||||
@ -721,8 +732,8 @@ send_payment(struct lightningd *ld,
|
||||
&route[0].channel_id,
|
||||
&channel->peer->id);
|
||||
|
||||
return sendpay_fail(cmd, PAY_TRY_OTHER_ROUTE, NULL,
|
||||
fail, "First peer not ready");
|
||||
return sendpay_fail(cmd, payment, PAY_TRY_OTHER_ROUTE,
|
||||
NULL, fail, "First peer not ready");
|
||||
}
|
||||
|
||||
/* Copy channels used along the route. */
|
||||
|
@ -26,6 +26,7 @@ void json_add_payment_fields(struct json_stream *response,
|
||||
|
||||
/* This json will be also used in 'sendpay_failure' notifictaion. */
|
||||
void json_sendpay_fail_fields(struct json_stream *js,
|
||||
const struct wallet_payment *t,
|
||||
int pay_errcode,
|
||||
const u8 *onionreply,
|
||||
const struct routing_failure *fail);
|
||||
|
Loading…
Reference in New Issue
Block a user