offers: include the payer_note field in the invoice if it's in the request.

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

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-07-02 09:41:35 +09:30
parent 18b6aa5e66
commit 12dd3a439b
3 changed files with 24 additions and 0 deletions

View File

@ -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",
@ -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))
@ -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))

View File

@ -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.
@ -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.

View File

@ -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));