|
17 | 17 | #include <lightningd/peer_htlcs.h> |
18 | 18 | #include <wallet/invoices.h> |
19 | 19 |
|
| 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 | + |
20 | 44 | /* Routing failure object */ |
21 | 45 | struct routing_failure { |
22 | 46 | unsigned int erring_index; |
@@ -137,7 +161,8 @@ add_waitsendpay_waiter_(struct lightningd *ld, |
137 | 161 | /* Outputs fields, not a separate object*/ |
138 | 162 | void json_add_payment_fields(struct json_stream *response, |
139 | 163 | const struct wallet_payment *t) |
140 | | -{ |
| 164 | +{ |
| 165 | + const char *description = NULL; |
141 | 166 | json_add_u64(response, "created_index", t->id); |
142 | 167 | json_add_u64(response, "id", t->id); |
143 | 168 | json_add_sha256(response, "payment_hash", &t->payment_hash); |
@@ -176,13 +201,18 @@ void json_add_payment_fields(struct json_stream *response, |
176 | 201 | if (t->label) |
177 | 202 | json_add_string(response, "label", t->label); |
178 | 203 | 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 | +} |
184 | 212 | if (t->description) |
185 | 213 | json_add_string(response, "description", t->description); |
| 214 | + else if (description) |
| 215 | + json_add_string(response, "description", description); |
186 | 216 |
|
187 | 217 | if (t->failonion) |
188 | 218 | json_add_hex(response, "erroronion", t->failonion, |
|
0 commit comments