Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@
#include <lightningd/peer_htlcs.h>
#include <wallet/invoices.h>

/* Helper functions for extracting description from bolt11/12 string*/
static const char *decode_bolt11_description_simple(const tal_t *ctx,
const char *invstr)
{
char *fail;
struct bolt11 *b11 = bolt11_decode(ctx, invstr, NULL, NULL, NULL, &fail);
if (!b11)
return NULL;
if (b11->description)
return tal_strdup(ctx, b11->description);
return NULL;
}

static const char *decode_bolt12_description(const tal_t *ctx, const char *invstr) {
char *fail;
struct tlv_invoice *tinv = invoice_decode(ctx, invstr, strlen(invstr),
NULL, NULL, &fail);
if (!tinv)
return NULL;
if (tinv->invreq_payer_note)
return tal_strdup(ctx, tinv->invreq_payer_note);
return NULL;
}

/* Routing failure object */
struct routing_failure {
unsigned int erring_index;
Expand Down Expand Up @@ -138,6 +162,7 @@ add_waitsendpay_waiter_(struct lightningd *ld,
void json_add_payment_fields(struct json_stream *response,
const struct wallet_payment *t)
{
const char *description = NULL;
json_add_u64(response, "created_index", t->id);
json_add_u64(response, "id", t->id);
json_add_sha256(response, "payment_hash", &t->payment_hash);
Expand Down Expand Up @@ -176,13 +201,18 @@ void json_add_payment_fields(struct json_stream *response,
if (t->label)
json_add_string(response, "label", t->label);
if (t->invstring) {
if (strstarts(t->invstring, "lni"))
json_add_string(response, "bolt12", t->invstring);
else
json_add_string(response, "bolt11", t->invstring);
}
if (strstarts(t->invstring, "lni")) {
json_add_string(response, "bolt12", t->invstring);
description = decode_bolt12_description(response, t->invstring);
} else {
json_add_string(response, "bolt11", t->invstring);
description = decode_bolt11_description_simple(response, t->invstring);
}
}
if (t->description)
json_add_string(response, "description", t->description);
else if (description)
json_add_string(response, "description", description);

if (t->failonion)
json_add_hex(response, "erroronion", t->failonion,
Expand Down
Loading