diff --git a/doc/lightning-sendinvoice.7 b/doc/lightning-sendinvoice.7 index 14fdbc9e9..815d3b11f 100644 --- a/doc/lightning-sendinvoice.7 +++ b/doc/lightning-sendinvoice.7 @@ -41,15 +41,8 @@ but the invoice will still be valid, and the caller should monitor it\. .SH RETURN VALUE -On success, an object as follows is returned: +On success, an object as per \fBlightning-waitinvoice\fR(7)\. -.RS -.IP \[bu] -\fIinvstring\fR: the bolt12-encoded invoice string we sent (now paid), starting with "lni1"\. -.IP \[bu] -\fImsat\fR: the amount they paid\. - -.RE The following error codes may occur: @@ -78,4 +71,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:0ffd4c0967f4aa7ffb2f14ed4658dbe4ef79926a08acf0534db47fdd8bd1b6bc +\" SHA256STAMP:403f142342802de658c6721a5caed11a9753fb1b437feceb19bcae30c79a4615 diff --git a/doc/lightning-sendinvoice.7.md b/doc/lightning-sendinvoice.7.md index dd68d16fe..0b4a44eb5 100644 --- a/doc/lightning-sendinvoice.7.md +++ b/doc/lightning-sendinvoice.7.md @@ -37,10 +37,7 @@ but the invoice will still be valid, and the caller should monitor it. RETURN VALUE ------------ -On success, an object as follows is returned: - -* *invstring*: the bolt12-encoded invoice string we sent (now paid), starting with "lni1". -* *msat*: the amount they paid. +On success, an object as per lightning-waitinvoice(7). The following error codes may occur: - -1: Catchall nonspecific error. diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 064553b6d..81add6395 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -973,21 +973,20 @@ static struct command_result *invoice_payment(struct command *cmd, json_to_msat(buf, msattok, &msat); list_for_each(&sent_list, i, list) { - struct json_stream *out; + struct out_req *req; if (!i->inv) continue; if (!preimage_eq(&preimage, &i->inv_preimage)) continue; - /* It was paid! Success. */ - /* FIXME: Return as per waitinvoice */ - out = jsonrpc_stream_success(i->cmd); - json_add_string(out, "invstring", invoice_encode(tmpctx, i->inv)); - json_add_string(out, "msat", - type_to_string(tmpctx, struct amount_msat, - &msat)); - discard_result(command_finished(i->cmd, out)); + /* It was paid! Success. Return as per waitinvoice. */ + req = jsonrpc_request_start(cmd->plugin, i->cmd, "waitinvoice", + &forward_result, + &forward_error, + i); + json_add_escaped_string(req->js, "label", i->inv_label); + discard_result(send_outreq(cmd->plugin, req)); break; } return command_hook_success(cmd); diff --git a/tests/test_pay.py b/tests/test_pay.py index 51c30601d..7d39ddf6b 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4003,6 +4003,18 @@ def test_sendinvoice(node_factory, bitcoind): out = l2.rpc.call('sendinvoice', {'offer': offer, 'label': 'test sendinvoice 1'}) print(out) + assert out['label'] == 'test sendinvoice 1' + assert out['description'] == 'simple test' + assert 'bolt12' in out + assert 'payment_hash' in out + assert out['status'] == 'paid' + assert 'payment_preimage' in out + assert 'expires_at' in out + assert out['msatoshi'] == 100000000 + assert out['amount_msat'] == Millisatoshi(100000000) + assert 'pay_index' in out + assert out['msatoshi_received'] == 100000000 + assert out['amount_received_msat'] == Millisatoshi(100000000) # Note, if we're slow, this fails with "Offer no longer available", # *but* if it hasn't heard about payment success yet, l2 will fail