Browse Source

sendinvoice: call waitinvoice directly to on invoice payment.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa
Rusty Russell 4 years ago
parent
commit
d867fab3a7
  1. 11
      doc/lightning-sendinvoice.7
  2. 5
      doc/lightning-sendinvoice.7.md
  3. 17
      plugins/fetchinvoice.c
  4. 12
      tests/test_pay.py

11
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<rusty@rustcorp.com.au\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:0ffd4c0967f4aa7ffb2f14ed4658dbe4ef79926a08acf0534db47fdd8bd1b6bc
\" SHA256STAMP:403f142342802de658c6721a5caed11a9753fb1b437feceb19bcae30c79a4615

5
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.

17
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);

12
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

Loading…
Cancel
Save