pay/sendpay: also store description in case bolt11 uses description_hash.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-04-02 13:03:35 +10:30
parent d5c736fe86
commit e47786da04
13 changed files with 82 additions and 11 deletions

View File

@@ -65,6 +65,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
p->temp_exclusion = NULL;
p->failroute_retry = false;
p->invstring = NULL;
p->description = NULL;
p->routetxt = NULL;
p->max_htlcs = UINT32_MAX;
p->aborterror = NULL;
@@ -1568,6 +1569,9 @@ static struct command_result *payment_createonion_success(struct command *cmd,
/* FIXME: rename parameter to invstring */
json_add_string(req->js, "bolt11", p->invstring);
if (p->description)
json_add_string(req->js, "description", p->description);
if (p->destination)
json_add_node_id(req->js, "destination", p->destination);
@@ -3559,6 +3563,8 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p)
* they'll be used when aggregating the payments
* again. */
c->invstring = tal_strdup(c, p->invstring);
if (p->description)
c->description = tal_strdup(c, p->description);
/* Get ~ target, but don't exceed amt */
c->amount = fuzzed_near(target, amt);

View File

@@ -259,6 +259,9 @@ struct payment {
* by the invoice. */
const char *invstring;
/* Description, usually set if bolt11 has only description_hash */
const char *description;
/* If this is paying a local offer, this is the one (sendpay ensures we
* don't pay twice for single-use offers) */
struct sha256 *local_offer_id;

View File

@@ -273,6 +273,8 @@ struct pay_mpp {
/* Optional label (of first one!) */
const jsmntok_t *label;
/* Optional description (used for bolt11 with description_hash) */
const jsmntok_t *description;
/* Optional preimage (iff status is successful) */
const jsmntok_t *preimage;
/* Only counts "complete" or "pending" payments. */
@@ -373,7 +375,8 @@ static void add_new_entry(struct json_stream *ret,
json_object_start(ret, NULL);
if (pm->invstring)
json_add_invstring(ret, pm->invstring);
if (pm->description)
json_add_tok(ret, "description", pm->description, buf);
if (pm->destination)
json_add_tok(ret, "destination", pm->destination, buf);
@@ -465,6 +468,7 @@ static struct command_result *listsendpays_done(struct command *cmd,
pm->invstring = tal_steal(pm, invstr);
pm->destination = json_get_member(buf, t, "destination");
pm->label = json_get_member(buf, t, "label");
pm->description = json_get_member(buf, t, "description");
pm->preimage = NULL;
pm->amount_sent = AMOUNT_MSAT(0);
pm->amount = talz(pm, struct amount_msat);
@@ -968,6 +972,7 @@ static struct command_result *json_pay(struct command *cmd,
p = payment_new(cmd, cmd, NULL /* No parent */, paymod_mods);
p->invstring = tal_steal(p, b11str);
p->description = tal_steal(p, description);
if (!bolt12_has_prefix(b11str)) {
b11 =