jsonrpc: Add groupid to sendpay and sendonion

Also add `groupid` to the payment fields so we can retrieve them too.
This commit is contained in:
Christian Decker 2021-09-28 18:05:33 +02:00 committed by Rusty Russell
parent ba4be0313b
commit a1f509e4b5
11 changed files with 44 additions and 10 deletions

View file

@ -45,6 +45,7 @@ On success, an object containing **payments** is returned. It is an array of ob
- **partid** (u64, optional): unique ID within this (multi-part) payment
- **destination** (pubkey, optional): the final destination of the payment if known
- **amount_msat** (msat, optional): the amount the destination received, if known
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **payment_preimage** (hex, optional): proof of payment (always 64 characters)
- **label** (string, optional): the label, if given to sendpay
- **bolt11** (string, optional): the bolt11 string (if pay supplied one)
@ -100,4 +101,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:59b05702a120f92395c71c392d934ccfba343f5ffa98cfc715c657d312d457c2)
[comment]: # ( SHA256STAMP:2fe7a92ce837282fc473f8f56b2040910fb1dcf8d0d7768fda5695dd5a5b4f01)

View file

@ -29,6 +29,7 @@ On success, an object containing **payments** is returned. It is an array of ob
- **status** (string): status of the payment (one of "pending", "failed", "complete")
- **created_at** (u64): the UNIX timestamp showing when this payment was initiated
- **amount_sent_msat** (msat): The amount sent
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **amount_msat** (msat, optional): The amount delivered to destination (if known)
- **destination** (pubkey, optional): the final destination of the payment if known
- **label** (string, optional): the label, if given to sendpay
@ -59,4 +60,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:e6a71b4e168fe64b774dc4738a46470edf00b4566ae2927166621ba79f89ca79)
[comment]: # ( SHA256STAMP:2cc3f9f1b830c2ef9f2027c79547af7e2096313b68c045c517870659f3499d38)

View file

@ -127,4 +127,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[bolt04]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
[comment]: # ( SHA256STAMP:cdb61326a6ac1481fa9aae6a0ab13cb6a0e70f4ae7b0af5228808fa0015ad9b6)
[comment]: # ( SHA256STAMP:aeade675a3e42ffc0b7be2bfefe429fdc5b52e6f4000687db90dfffd5b0b588d)

View file

@ -61,6 +61,7 @@ On success, an object is returned, containing:
- **status** (string): status of the payment (could be complete if already sent previously) (one of "pending", "complete")
- **created_at** (u64): the UNIX timestamp showing when this payment was initiated
- **amount_sent_msat** (msat): The amount sent
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **amount_msat** (msat, optional): The amount delivered to destination (if known)
- **destination** (pubkey, optional): the final destination of the payment if known
- **label** (string, optional): the *label*, if given to sendpay
@ -126,4 +127,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:4dd638126f66c3c4b233b3bb0aaeec5f225a80ec7186edd1901f8ed4cf23380e)
[comment]: # ( SHA256STAMP:f7572da509a442c08f73460c042d8e2aa950747ce175ebb9b89d32b88add6de6)

View file

@ -39,6 +39,7 @@ On success, an object is returned, containing:
- **status** (string): status of the payment (always "complete")
- **created_at** (u64): the UNIX timestamp showing when this payment was initiated
- **amount_sent_msat** (msat): The amount sent
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **amount_msat** (msat, optional): The amount delivered to destination (if known)
- **destination** (pubkey, optional): the final destination of the payment if known
- **label** (string, optional): the label, if given to sendpay
@ -100,4 +101,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:7a51daf13b7275c49a6c6f411de005998c674e9d5290ee83f3b41ea711da42f1)
[comment]: # ( SHA256STAMP:c40814f929fb6d741e0724ba75f0833e52fae1f03ed2d1fac9a8ba1186ceabab)

View file

@ -52,6 +52,10 @@
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"groupid": {
"type": "u64",
"description": "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash"
},
"payment_preimage": {
"type": "hex",
"description": "proof of payment",

View file

@ -15,6 +15,10 @@
"type": "u64",
"description": "unique ID for this payment attempt"
},
"groupid": {
"type": "u64",
"description": "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash"
},
"payment_hash": {
"type": "hex",
"description": "the hash of the *payment_preimage* which will prove payment",
@ -76,6 +80,7 @@
"required": [ "payment_preimage" ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },
@ -110,6 +115,7 @@
"required": [ ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },
@ -142,6 +148,7 @@
"required": [ ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },

View file

@ -75,6 +75,7 @@
"amount_msat": { },
"destination": { },
"created_at": { },
"groupid": { },
"msatoshi_sent": { },
"amount_sent_msat": { },
"label": { },
@ -109,6 +110,7 @@
"amount_msat": { },
"destination": { },
"created_at": { },
"groupid": { },
"msatoshi_sent": { },
"amount_sent_msat": { },
"label": { },

View file

@ -8,6 +8,10 @@
"type": "u64",
"description": "unique ID for this payment attempt"
},
"groupid": {
"type": "u64",
"description": "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash"
},
"payment_hash": {
"type": "hex",
"description": "the hash of the *payment_preimage* which will prove payment",
@ -73,6 +77,7 @@
"required": [ "payment_preimage" ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },
@ -108,6 +113,7 @@
"required": [ "message" ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },

View file

@ -8,6 +8,10 @@
"type": "u64",
"description": "unique ID for this payment attempt"
},
"groupid": {
"type": "u64",
"description": "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash"
},
"payment_hash": {
"type": "hex",
"description": "the hash of the *payment_preimage* which will prove payment",
@ -73,6 +77,7 @@
"required": [ "payment_preimage" ],
"properties": {
"id": { },
"groupid": { },
"payment_hash": { },
"status": { },
"msatoshi": { },

View file

@ -111,6 +111,7 @@ void json_add_payment_fields(struct json_stream *response,
{
json_add_u64(response, "id", t->id);
json_add_sha256(response, "payment_hash", &t->payment_hash);
json_add_u64(response, "groupid", t->groupid);
if (t->partid)
json_add_u64(response, "partid", t->partid);
if (t->destination != NULL)
@ -839,6 +840,7 @@ send_payment_core(struct lightningd *ld,
struct command *cmd,
const struct sha256 *rhash,
u64 partid,
u64 group,
const struct route_hop *first_hop,
struct amount_msat msat,
struct amount_msat total_msat,
@ -1038,6 +1040,7 @@ send_payment_core(struct lightningd *ld,
payment->id = 0;
payment->payment_hash = *rhash;
payment->partid = partid;
payment->groupid = group;
if (destination)
payment->destination = tal_dup(payment, struct node_id, destination);
else
@ -1083,6 +1086,7 @@ send_payment(struct lightningd *ld,
struct command *cmd,
const struct sha256 *rhash,
u64 partid,
u64 group,
const struct route_hop *route,
struct amount_msat msat,
struct amount_msat total_msat,
@ -1169,7 +1173,7 @@ send_payment(struct lightningd *ld,
type_to_string(tmpctx, struct amount_msat, &route[0].amount),
n_hops, type_to_string(tmpctx, struct amount_msat, &msat));
packet = create_onionpacket(tmpctx, path, ROUTING_INFO_SIZE, &path_secrets);
return send_payment_core(ld, cmd, rhash, partid, &route[0],
return send_payment_core(ld, cmd, rhash, partid, group, &route[0],
msat, total_msat, label, invstring,
packet, &ids[n_hops - 1], ids,
channels, path_secrets, local_offer_id);
@ -1245,7 +1249,7 @@ static struct command_result *json_sendonion(struct command *cmd,
struct node_id *destination;
struct secret *path_secrets;
struct amount_msat *msat;
u64 *partid;
u64 *partid, *group;
struct sha256 *local_offer_id = NULL;
if (!param(cmd, buffer, params,
@ -1260,6 +1264,7 @@ static struct command_result *json_sendonion(struct command *cmd,
p_opt_def("msatoshi", param_msat, &msat, AMOUNT_MSAT(0)),
p_opt("destination", param_node_id, &destination),
p_opt("localofferid", param_sha256, &local_offer_id),
p_opt_def("groupid", param_u64, &group, 0),
NULL))
return command_param_failed();
@ -1271,7 +1276,7 @@ static struct command_result *json_sendonion(struct command *cmd,
"with failcode=%d",
failcode);
return send_payment_core(ld, cmd, payment_hash, *partid,
return send_payment_core(ld, cmd, payment_hash, *partid, *group,
first_hop, *msat, AMOUNT_MSAT(0),
label, invstring, packet, destination, NULL, NULL,
path_secrets, local_offer_id);
@ -1397,7 +1402,7 @@ static struct command_result *json_sendpay(struct command *cmd,
struct route_hop *route;
struct amount_msat *msat;
const char *invstring, *label;
u64 *partid;
u64 *partid, *group;
struct secret *payment_secret;
struct sha256 *local_offer_id = NULL;
@ -1412,6 +1417,7 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("payment_secret", param_secret, &payment_secret),
p_opt_def("partid", param_u64, &partid, 0),
p_opt("localofferid", param_sha256, &local_offer_id),
p_opt_def("groupid", param_u64, &group, 0),
NULL))
return command_param_failed();
@ -1451,7 +1457,7 @@ static struct command_result *json_sendpay(struct command *cmd,
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"partid requires payment_secret");
return send_payment(cmd->ld, cmd, rhash, *partid,
return send_payment(cmd->ld, cmd, rhash, *partid, *group,
route,
final_amount,
msat ? *msat : final_amount,