invoice: output payment_secret in JSON.

This makes it easier to access (rather than decoding bolt11).

Changelog-Added: JSON-RPC: `invoice` now outputs explicit `payment_secret` it its own field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-07-12 08:34:33 +09:30
committed by neil saitug
parent 246d230486
commit 3f5d5a1de5
5 changed files with 20 additions and 3 deletions

View File

@@ -85,6 +85,8 @@ On success, an object is returned, containing:
.IP \[bu]
\fBpayment_hash\fR (hex): the hash of the \fIpayment_preimage\fR which will prove payment (always 64 characters)
.IP \[bu]
\fBpayment_secret\fR (hex): the \fIpayment_secret\fR to place in the onion (always 64 characters)
.IP \[bu]
\fBexpires_at\fR (u64): UNIX timestamp of when invoice expires
.RE
@@ -136,4 +138,4 @@ Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:f27f015d8d612d280a8abca6930dbd42ef37fdac00bff1b114d1fd9138b15097
\" SHA256STAMP:1617a52d2c9c5adbee4b410d15889a5f1c32e0a2fb2982dac82c5e74fb028ff3

View File

@@ -75,6 +75,7 @@ RETURN VALUE
On success, an object is returned, containing:
- **bolt11** (string): the bolt11 string
- **payment_hash** (hex): the hash of the *payment_preimage* which will prove payment (always 64 characters)
- **payment_secret** (hex): the *payment_secret* to place in the onion (always 64 characters)
- **expires_at** (u64): UNIX timestamp of when invoice expires
The following warnings may also be returned:
@@ -111,4 +112,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:e63e87b91a14b8ae823ae67fc25315bc31b15a14378c05f4c972830bf3515af1)
[comment]: # ( SHA256STAMP:cba838098a7f95ab74906f387b2d67777b33ccc40349cb9a8ef1f7c9cc28c6ef)

View File

@@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [ "payment_hash", "expires_at", "bolt11" ],
"required": [ "payment_hash", "expires_at", "bolt11", "payment_secret" ],
"properties": {
"bolt11": {
"type": "string",
@@ -14,6 +14,12 @@
"maxLength": 64,
"minLength": 64
},
"payment_secret": {
"type": "hex",
"description": "the *payment_secret* to place in the onion",
"maxLength": 64,
"minLength": 64
},
"expires_at": {
"type": "u64",
"description": "UNIX timestamp of when invoice expires"

View File

@@ -855,6 +855,7 @@ invoice_complete(struct invoice_info *info,
struct invoice invoice;
char *b11enc;
const struct invoice_details *details;
struct secret payment_secret;
struct wallet *wallet = info->cmd->ld->wallet;
b11enc = bolt11_encode(info, info->b11, false,
@@ -904,6 +905,8 @@ invoice_complete(struct invoice_info *info,
json_add_sha256(response, "payment_hash", &details->rhash);
json_add_u64(response, "expires_at", details->expiry_time);
json_add_string(response, "bolt11", details->invstring);
invoice_secret(&details->r, &payment_secret);
json_add_secret(response, "payment_secret", &payment_secret);
notify_invoice_creation(info->cmd->ld, info->b11->msat,
info->payment_preimage, info->label);

View File

@@ -334,6 +334,11 @@ void json_add_node_id(struct json_stream *response UNNEEDED,
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,
const struct secret *secret UNNEEDED)
{ fprintf(stderr, "json_add_secret called!\n"); abort(); }
/* Generated stub for json_add_sha256 */
void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct sha256 *hash UNNEEDED)