Skip to content

Commit b3ff08b

Browse files
committed
gRPC: lightningd: Fix empty description field in listpays & listsendpays
Changelog-Added: Fix empty `description` field for gRPC `listpays` and `listsendpays`. No schema change required; the field already existed but was not populated.
1 parent bb5b8d7 commit b3ff08b

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

lightningd/pay.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@
1717
#include <lightningd/peer_htlcs.h>
1818
#include <wallet/invoices.h>
1919

20+
/* Helper functions for extracting description from bolt11/12 string*/
21+
static const char *decode_bolt11_description_simple(const tal_t *ctx,
22+
const char *invstr)
23+
{
24+
char *fail;
25+
struct bolt11 *b11 = bolt11_decode(ctx, invstr, NULL, NULL, NULL, &fail);
26+
if (!b11)
27+
return NULL;
28+
if (b11->description)
29+
return tal_strdup(ctx, b11->description);
30+
return NULL;
31+
}
32+
33+
static const char *decode_bolt12_description(const tal_t *ctx, const char *invstr) {
34+
char *fail;
35+
struct tlv_invoice *tinv = invoice_decode(ctx, invstr, strlen(invstr),
36+
NULL, NULL, &fail);
37+
if (!tinv)
38+
return NULL;
39+
if (tinv->invreq_payer_note)
40+
return tal_strdup(ctx, tinv->invreq_payer_note);
41+
return NULL;
42+
}
43+
2044
/* Routing failure object */
2145
struct routing_failure {
2246
unsigned int erring_index;
@@ -137,7 +161,8 @@ add_waitsendpay_waiter_(struct lightningd *ld,
137161
/* Outputs fields, not a separate object*/
138162
void json_add_payment_fields(struct json_stream *response,
139163
const struct wallet_payment *t)
140-
{
164+
{
165+
const char *description = NULL;
141166
json_add_u64(response, "created_index", t->id);
142167
json_add_u64(response, "id", t->id);
143168
json_add_sha256(response, "payment_hash", &t->payment_hash);
@@ -176,13 +201,18 @@ void json_add_payment_fields(struct json_stream *response,
176201
if (t->label)
177202
json_add_string(response, "label", t->label);
178203
if (t->invstring) {
179-
if (strstarts(t->invstring, "lni"))
180-
json_add_string(response, "bolt12", t->invstring);
181-
else
182-
json_add_string(response, "bolt11", t->invstring);
183-
}
204+
if (strstarts(t->invstring, "lni")) {
205+
json_add_string(response, "bolt12", t->invstring);
206+
description = decode_bolt12_description(response, t->invstring);
207+
} else {
208+
json_add_string(response, "bolt11", t->invstring);
209+
description = decode_bolt11_description_simple(response, t->invstring);
210+
}
211+
}
184212
if (t->description)
185213
json_add_string(response, "description", t->description);
214+
else if (description)
215+
json_add_string(response, "description", description);
186216

187217
if (t->failonion)
188218
json_add_hex(response, "erroronion", t->failonion,

0 commit comments

Comments
 (0)