Skip to content

Commit d8b934a

Browse files
lightningd: include offer_id in invoice_creation notification
When a BOLT 12 invoice is created via createinvoice and is associated with a local offer, include the offer_id in the invoice_creation event notification. This allows plugins to determine which offer triggered an invoice creation without having to call listinvoices for every created invoice. For bolt11 invoices and bolt12 invoices not associated with a local offer, the field is omitted. Fixes #8191 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f09f0c commit d8b934a

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

doc/developers-guide/plugin-development/event-notifications.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ A notification for topic `invoice_creation` is sent every time an invoice is cre
181181
}
182182
```
183183

184+
If the invoice is associated with a BOLT 12 offer, an `offer_id` field will be present:
185+
186+
```json
187+
{
188+
"invoice_creation": {
189+
"label": "unique-label-for-invoice",
190+
"preimage": "0000000000000000000000000000000000000000000000000000000000000000",
191+
"msat": 10000,
192+
"offer_id": "b1d1062abc09790a68be83e4c257614a57978e4053a954bfee5909ed71e23e03"
193+
}
194+
}
195+
```
196+
184197
Before version `23.11` the `msat` field was a string with msat-suffix, e.g: `"10000msat"`.
185198

186199
### `warning`

lightningd/invoice.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ invoice_complete(struct invoice_info *info,
872872
json_add_u64(response, "created_index", details->created_index);
873873

874874
notify_invoice_creation(info->cmd->ld, info->b11->msat,
875-
&info->payment_preimage, info->label);
875+
&info->payment_preimage, info->label, NULL);
876876

877877
if (warning_no_listincoming)
878878
json_add_string(response, "warning_listincoming",
@@ -1725,7 +1725,7 @@ static struct command_result *json_createinvoice(struct command *cmd,
17251725
NULL))
17261726
return fail_exists(cmd, label);
17271727

1728-
notify_invoice_creation(cmd->ld, b11->msat, preimage, label);
1728+
notify_invoice_creation(cmd->ld, b11->msat, preimage, label, NULL);
17291729
} else {
17301730
struct tlv_invoice *inv;
17311731
struct sha256 offer_id, *local_offer_id;
@@ -1822,7 +1822,7 @@ static struct command_result *json_createinvoice(struct command *cmd,
18221822
local_offer_id))
18231823
return fail_exists(cmd, label);
18241824

1825-
notify_invoice_creation(cmd->ld, &msat, preimage, label);
1825+
notify_invoice_creation(cmd->ld, &msat, preimage, label, local_offer_id);
18261826
}
18271827

18281828
response = json_stream_success(cmd);

lightningd/notification.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,30 @@ void notify_invoice_payment(struct lightningd *ld,
221221
static void invoice_creation_notification_serialize(struct json_stream *stream,
222222
const struct amount_msat *amount,
223223
const struct preimage *preimage,
224-
const struct json_escape *label)
224+
const struct json_escape *label,
225+
const struct sha256 *offer_id)
225226
{
226227
if (amount != NULL)
227228
json_add_amount_msat(stream, "msat", *amount);
228229

229230
json_add_preimage(stream, "preimage", preimage);
230231
json_add_escaped_string(stream, "label", label);
232+
if (offer_id)
233+
json_add_sha256(stream, "offer_id", offer_id);
231234
}
232235

233236
REGISTER_NOTIFICATION(invoice_creation)
234237

235238
void notify_invoice_creation(struct lightningd *ld,
236239
const struct amount_msat *amount,
237240
const struct preimage *preimage,
238-
const struct json_escape *label)
241+
const struct json_escape *label,
242+
const struct sha256 *offer_id)
239243
{
240244
struct jsonrpc_notification *n = notify_start(ld, "invoice_creation");
241245
if (!n)
242246
return;
243-
invoice_creation_notification_serialize(n->stream, amount, preimage, label);
247+
invoice_creation_notification_serialize(n->stream, amount, preimage, label, offer_id);
244248
notify_send(ld, n);
245249
}
246250

lightningd/notification.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void notify_invoice_payment(struct lightningd *ld,
4242
void notify_invoice_creation(struct lightningd *ld,
4343
const struct amount_msat *amount,
4444
const struct preimage *preimage,
45-
const struct json_escape *label);
45+
const struct json_escape *label,
46+
const struct sha256 *offer_id);
4647

4748
void notify_channel_opened(struct lightningd *ld,
4849
const struct node_id *node_id,

lightningd/test/run-invoice-select-inchan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ void notify_disconnect(struct lightningd *ld UNNEEDED, const struct node_id *nod
530530
void notify_invoice_creation(struct lightningd *ld UNNEEDED,
531531
const struct amount_msat *amount UNNEEDED,
532532
const struct preimage *preimage UNNEEDED,
533-
const struct json_escape *label UNNEEDED)
533+
const struct json_escape *label UNNEEDED,
534+
const struct sha256 *offer_id UNNEEDED)
534535
{ fprintf(stderr, "notify_invoice_creation called!\n"); abort(); }
535536
/* Generated stub for notify_invoice_payment */
536537
void notify_invoice_payment(struct lightningd *ld UNNEEDED,

0 commit comments

Comments
 (0)