Skip to content

Commit 881eb80

Browse files
ZmnSCPxjrustyrussell
authored andcommitted
payalgo: Make 'pay' return similar to 'listpayments'
1 parent 3c39bcc commit 881eb80

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lightningd/payalgo.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <lightningd/log.h>
1616
#include <lightningd/subd.h>
1717
#include <sodium/randombytes.h>
18+
#include <wallet/wallet.h>
1819

1920
/* Record of failures. */
2021
enum pay_failure_type {
@@ -208,15 +209,14 @@ add_pay_failure(struct pay *pay,
208209

209210
static void
210211
json_pay_success(struct pay *pay,
211-
const struct preimage *payment_preimage)
212+
const struct sendpay_result *r)
212213
{
213214
struct command *cmd = pay->cmd;
214215
struct json_result *response;
215216

216217
response = new_json_result(cmd);
217218
json_object_start(response, NULL);
218-
json_add_hex(response, "payment_preimage",
219-
payment_preimage, sizeof(*payment_preimage));
219+
json_add_payment_fields(response, r->payment);
220220
json_add_num(response, "getroute_tries", pay->getroute_tries);
221221
json_add_num(response, "sendpay_tries", pay->sendpay_tries);
222222
json_add_route(response, "route",
@@ -239,6 +239,15 @@ static void json_pay_failure(struct pay *pay,
239239

240240
switch (r->errorcode) {
241241
case PAY_IN_PROGRESS:
242+
json_object_start(data, NULL);
243+
json_add_num(data, "getroute_tries", pay->getroute_tries);
244+
json_add_num(data, "sendpay_tries", pay->sendpay_tries);
245+
json_add_payment_fields(data, r->payment);
246+
json_add_failures(data, "failures", &pay->pay_failures);
247+
json_object_end(data);
248+
msg = r->details;
249+
break;
250+
242251
case PAY_RHASH_ALREADY_USED:
243252
case PAY_STOPPED_RETRYING:
244253
json_object_start(data, NULL);
@@ -341,7 +350,7 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
341350
/* If we succeed, hurray */
342351
if (r->succeeded) {
343352
log_info(pay->cmd->ld->log, "pay(%p): Success", pay);
344-
json_pay_success(pay, &r->preimage);
353+
json_pay_success(pay, r);
345354
return;
346355
}
347356

@@ -552,11 +561,15 @@ static bool json_pay_try(struct pay *pay)
552561
static void json_pay_stop_retrying(struct pay *pay)
553562
{
554563
struct sendpay_result *sr;
564+
555565
sr = tal(pay, struct sendpay_result);
556566
sr->succeeded = false;
557567
if (pay->in_sendpay) {
558568
/* Still in sendpay. Return with PAY_IN_PROGRESS */
559569
sr->errorcode = PAY_IN_PROGRESS;
570+
sr->payment = wallet_payment_by_hash(sr,
571+
pay->cmd->ld->wallet,
572+
&pay->payment_hash);
560573
sr->details = "Stopped retrying during payment attempt; "
561574
"continue monitoring with "
562575
"pay or listpayments";

0 commit comments

Comments
 (0)