invoice: Allow "any" msatoshi, for amountless invoices.

Fixes: #534
This commit is contained in:
ZmnSCPxj 2018-01-10 01:28:44 +00:00 committed by Rusty Russell
parent caab95b922
commit 816298123f
3 changed files with 22 additions and 10 deletions

View File

@ -2,12 +2,12 @@
.\" Title: lightning-invoice
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 09/06/2016
.\" Date: 01/10/2018
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "LIGHTNING\-INVOICE" "7" "09/06/2016" "\ \&" "\ \&"
.TH "LIGHTNING\-INVOICE" "7" "01/10/2018" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@ -36,10 +36,12 @@ lightning-invoice \- Protocol for accepting payments\&.
.sp
The \fBinvoice\fR RPC command creates the expectation of a payment of a given amount of milli\-satoshi: it returns a unique token which another lightning daemon can use to pay this invoice\&.
.sp
The \fImsatoshi\fR can be the string "any", which creates an invoice that can be paid with any amount\&.
.sp
The \fIlabel\fR must be unique; it is never revealed to other nodes on the lightning network, but it can be used to query the status of this invoice\&.
.SH "RETURN VALUE"
.sp
On success, a hash is returned as \fIrhash\fR to be given to the payer\&. On failure, an error is returned and no invoice is created\&. If the lightning process fails before responding, the caller should use getinvoice(7) to query whether this invoice was created or not\&.
On success, a hash is returned as \fIrhash\fR to be given to the payer\&. It also returns a BOLT11 invoice as \fIbolt11\fR to be given to the payer\&. On failure, an error is returned and no invoice is created\&. If the lightning process fails before responding, the caller should use getinvoice(7) to query whether this invoice was created or not\&.
.SH "AUTHOR"
.sp
Rusty Russell <rusty@rustcorp\&.com\&.au> is mainly responsible\&.

View File

@ -16,6 +16,9 @@ The *invoice* RPC command creates the expectation of a payment of a
given amount of milli-satoshi: it returns a unique token which another
lightning daemon can use to pay this invoice.
The 'msatoshi' can be the string "any", which creates an invoice
that can be paid with any amount.
The 'label' must be unique; it is never revealed to other nodes on
the lightning network, but it can be used to query the status of this
invoice.
@ -24,6 +27,8 @@ RETURN VALUE
------------
On success, a hash is returned as 'rhash' to be given to the payer.
It also returns a BOLT11 invoice as 'bolt11' to be given to the
payer.
On failure, an error is returned and no invoice is created. If the
lightning process fails before responding, the caller should use
getinvoice(7) to query whether this invoice was created or not.

View File

@ -197,13 +197,18 @@ static void json_invoice(struct command *cmd,
sha256(&invoice->rhash, invoice->r.r, sizeof(invoice->r.r));
invoice->msatoshi = tal(invoice, u64);
if (!json_tok_u64(buffer, msatoshi, invoice->msatoshi)
|| *invoice->msatoshi == 0) {
command_fail(cmd, "'%.*s' is not a valid positive number",
msatoshi->end - msatoshi->start,
buffer + msatoshi->start);
return;
if (json_tok_streq(buffer, msatoshi, "any"))
invoice->msatoshi = NULL;
else {
invoice->msatoshi = tal(invoice, u64);
if (!json_tok_u64(buffer, msatoshi, invoice->msatoshi)
|| *invoice->msatoshi == 0) {
command_fail(cmd,
"'%.*s' is not a valid positive number",
msatoshi->end - msatoshi->start,
buffer + msatoshi->start);
return;
}
}
invoice->label = tal_strndup(invoice, buffer + label->start,