Skip to content

Commit

Permalink
offers: include the payer_note field in the invoice if it's in the re…
Browse files Browse the repository at this point in the history
…quest.

And list it in bolt12-cli decode, and the `decode` command.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jul 2, 2021
1 parent 2beb9c1 commit febeb60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions devtools/bolt12-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ static void print_payer_key(const struct pubkey32 *payer_key,
printf("\n");
}

static void print_payer_note(const char *payer_note)
{
printf("payer_note: %.*s\n",
(int)tal_bytelen(payer_note), payer_note);
}

static void print_timestamp(u64 timestamp)
{
printf("timestamp: %"PRIu64" (%s)\n",
Expand Down Expand Up @@ -535,6 +541,8 @@ int main(int argc, char *argv[])
print_chains(invreq->chains);
if (must_have(invreq, payer_key))
print_payer_key(invreq->payer_key, invreq->payer_info);
if (invreq->payer_note)
print_payer_note(invreq->payer_note);
if (must_have(invreq, offer_id))
print_offer_id(invreq->offer_id);
if (must_have(invreq, amount))
Expand Down Expand Up @@ -627,6 +635,8 @@ int main(int argc, char *argv[])
print_payer_key(invoice->payer_key, invoice->payer_info);
if (must_have(invoice, timestamp))
print_timestamp(*invoice->timestamp);
if (invoice->payer_note)
print_payer_note(invoice->payer_note);
print_relative_expiry(invoice->timestamp,
invoice->relative_expiry);
if (must_have(invoice, payment_hash))
Expand Down
6 changes: 6 additions & 0 deletions plugins/offers.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ static void json_add_b12_invoice(struct json_stream *js,
json_add_pubkey32(js, "payer_key", invoice->payer_key);
if (invoice->payer_info)
json_add_hex_talarr(js, "payer_info", invoice->payer_info);
if (invoice->payer_note)
json_add_stringn(js, "payer_note", invoice->payer_note,
tal_bytelen(invoice->payer_note));

/* BOLT-offers #12:
* - MUST reject the invoice if `timestamp` is not present.
Expand Down Expand Up @@ -663,6 +666,9 @@ static void json_add_invoice_request(struct json_stream *js,
}
if (invreq->payer_info)
json_add_hex_talarr(js, "payer_info", invreq->payer_info);
if (invreq->payer_note)
json_add_stringn(js, "payer_note", invreq->payer_note,
tal_bytelen(invreq->payer_note));

/* BOLT-offers #12:
* - MUST fail the request if there is no `payer_signature` field.
Expand Down
8 changes: 8 additions & 0 deletions plugins/offers_invreq_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,14 @@ static struct command_result *listoffers_done(struct command *cmd,
ir->inv->payer_info
= tal_dup_talarr(ir->inv, u8, ir->invreq->payer_info);

/* BOLT-offers #12:
* - MUST set (or not set) `payer_note` exactly as the invoice_request
* did, or MUST not set it.
*/
/* i.e. we don't have to do anything, but we do. */
ir->inv->payer_note
= tal_dup_talarr(ir->inv, char, ir->invreq->payer_note);

randombytes_buf(&ir->preimage, sizeof(ir->preimage));
ir->inv->payment_hash = tal(ir->inv, struct sha256);
sha256(ir->inv->payment_hash, &ir->preimage, sizeof(ir->preimage));
Expand Down

0 comments on commit febeb60

Please sign in to comment.