Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'invoice' command returning preimage. #3295

Merged
merged 3 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/lightning-invoice.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions doc/lightning-listinvoices.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions doc/lightning-listinvoices.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ if it exists, or the status of all invoices if given no argument.
RETURN VALUE
------------

On success, an array *invoices* of objects is returned. Each object
contains *label*, *payment\_hash*, *status* (one of *unpaid*, *paid* or
*expired*), and *expiry\_time* (a UNIX timestamp). If the *msatoshi*
argument to lightning-invoice(7) was not "any", there will be an
*msatoshi* field as a number, and *amount\_msat* as the same number
ending in *msat*. If the invoice *status* is *paid*, there will be a
*pay\_index* field and an *msatoshi\_received* field (which may be
slightly greater than *msatoshi* as some overpaying is permitted to
allow clients to obscure payment paths); there will also be an
*amount\_received\_msat* field with the same number as
*msatoshi\_received* but ending in *msat*.
On success, an array *invoices* of objects is returned. Each object contains
*label*, *payment\_hash*, *status* (one of *unpaid*, *paid* or *expired*),
*payment\_preimage* (for paid invoices), and *expiry\_time* (a UNIX
timestamp). If the *msatoshi* argument to lightning-invoice(7) was not "any",
there will be an *msatoshi* field as a number, and *amount\_msat* as the same
number ending in *msat*. If the invoice *status* is *paid*, there will be a
*pay\_index* field and an *msatoshi\_received* field (which may be slightly
greater than *msatoshi* as some overpaying is permitted to allow clients to
obscure payment paths); there will also be an *amount\_received\_msat* field
with the same number as *msatoshi\_received* but ending in *msat*.

AUTHOR
------
Expand Down
4 changes: 2 additions & 2 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static void json_add_invoice(struct json_stream *response,
"msatoshi_received",
"amount_received_msat");
json_add_u64(response, "paid_at", inv->paid_timestamp);
json_add_preimage(response, "payment_preimage", &inv->r);
}
if (inv->description)
json_add_string(response, "description", inv->description);
Expand Down Expand Up @@ -138,8 +139,7 @@ invoice_payment_serialize(struct invoice_payment_hook_payload *payload,
{
json_object_start(stream, "payment");
json_add_escaped_string(stream, "label", payload->label);
json_add_hex(stream, "preimage",
&payload->preimage, sizeof(payload->preimage));
json_add_preimage(stream, "preimage", &payload->preimage);
json_add_string(stream, "msat",
type_to_string(tmpctx, struct amount_msat,
&payload->msat));
Expand Down
6 changes: 6 additions & 0 deletions lightningd/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ void json_add_sha256(struct json_stream *result, const char *fieldname,
json_add_hex(result, fieldname, hash, sizeof(*hash));
}

void json_add_preimage(struct json_stream *result, const char *fieldname,
const struct preimage *preimage)
{
json_add_hex(result, fieldname, preimage, sizeof(*preimage));
}

/**
* segwit_addr_net_decode - Try to decode a Bech32 address and detect
* testnet/mainnet/regtest/signet
Expand Down
4 changes: 4 additions & 0 deletions lightningd/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct json_stream;
struct pubkey;
struct node_id;
struct sha256;
struct preimage;
struct short_channel_id;
struct wallet_payment;
struct wallet_tx;
Expand Down Expand Up @@ -206,6 +207,9 @@ void json_add_time(struct json_stream *result, const char *fieldname,
void json_add_sha256(struct json_stream *result, const char *fieldname,
const struct sha256 *hash);

void json_add_preimage(struct json_stream *result, const char *fieldname,
const struct preimage *preimage);

struct command_result *param_bitcoin_address(struct command *cmd,
const char *name,
const char *buffer,
Expand Down
5 changes: 2 additions & 3 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ void json_add_payment_fields(struct json_stream *response,
break;
}
if (t->payment_preimage)
json_add_hex(response, "payment_preimage",
t->payment_preimage,
sizeof(*t->payment_preimage));
json_add_preimage(response, "payment_preimage",
t->payment_preimage);
if (t->label)
json_add_string(response, "label", t->label);
if (t->bolt11)
Expand Down
8 changes: 4 additions & 4 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ void json_add_escaped_string(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED,
const struct json_escape *esc TAKES UNNEEDED)
{ fprintf(stderr, "json_add_escaped_string called!\n"); abort(); }
/* Generated stub for json_add_hex */
void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_add_hex called!\n"); abort(); }
/* Generated stub for json_add_hex_talarr */
void json_add_hex_talarr(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED,
Expand All @@ -194,6 +190,10 @@ void json_add_node_id(struct json_stream *response UNNEEDED,
void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
unsigned int value UNNEEDED)
{ fprintf(stderr, "json_add_num called!\n"); abort(); }
/* Generated stub for json_add_preimage */
void json_add_preimage(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct preimage *preimage UNNEEDED)
{ fprintf(stderr, "json_add_preimage called!\n"); abort(); }
/* Generated stub for json_add_secret */
void json_add_secret(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
Expand Down
1 change: 1 addition & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def only_one(arr):
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'paid'
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['pay_index'] == 1
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['msatoshi_received'] == rs['msatoshi']
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['payment_preimage'] == preimage

# Balances should reflect it.
def check_balances():
Expand Down