MCPcopy Create free account
hub / github.com/ElementsProject/lightning / add_stub_blindedpath

Function add_stub_blindedpath

lightningd/invoice.c:1619–1670  ·  view source on GitHub ↗

This is only if we're a public node; otherwise, the offers plugin * will have populated a real blinded path */

Source from the content-addressed store, hash-verified

1617/* This is only if we're a public node; otherwise, the offers plugin
1618 * will have populated a real blinded path */
1619static void add_stub_blindedpath(const tal_t *ctx,
1620 struct lightningd *ld,
1621 struct tlv_invoice *inv)
1622{
1623 struct blinded_path *path;
1624 struct privkey path_key;
1625 struct tlv_encrypted_data_tlv *tlv;
1626
1627 path = tal(NULL, struct blinded_path);
1628 sciddir_or_pubkey_from_pubkey(&path->first_node_id, &ld->our_pubkey);
1629 randbytes(&path_key, sizeof(path_key));
1630 if (!pubkey_from_privkey(&path_key, &path->first_path_key))
1631 abort();
1632 path->path = tal_arr(path, struct blinded_path_hop *, 1);
1633 path->path[0] = tal(path->path, struct blinded_path_hop);
1634
1635 /* A message in a bottle to ourselves: match it with
1636 * the invoice: we assume the payment_hash is unique! */
1637 tlv = tlv_encrypted_data_tlv_new(tmpctx);
1638 tlv->path_id = bolt12_path_id(inv,
1639 &ld->invoicesecret_base,
1640 inv->invoice_payment_hash);
1641
1642 path->path[0]->encrypted_recipient_data
1643 = encrypt_tlv_encrypted_data(path->path[0],
1644 &path_key,
1645 &path->first_node_id.pubkey,
1646 tlv,
1647 NULL,
1648 &path->path[0]->blinded_node_id);
1649
1650 inv->invoice_paths = tal_arr(inv, struct blinded_path *, 1);
1651 inv->invoice_paths[0] = tal_steal(inv->invoice_paths, path);
1652
1653 /* BOLT #12:
1654 * - MUST include `invoice_paths` containing one or more paths to the node.
1655 * - MUST specify `invoice_paths` in order of most-preferred to least-preferred if it has a preference.
1656 * - MUST include `invoice_blindedpay` with exactly one `blinded_payinfo` for each `blinded_path` in `paths`, in order.
1657 */
1658 inv->invoice_blindedpay = tal_arr(inv, struct blinded_payinfo *, 1);
1659 inv->invoice_blindedpay[0] = tal(inv->invoice_blindedpay,
1660 struct blinded_payinfo);
1661 inv->invoice_blindedpay[0]->fee_base_msat = 0;
1662 inv->invoice_blindedpay[0]->fee_proportional_millionths = 0;
1663 inv->invoice_blindedpay[0]->cltv_expiry_delta = ld->config.cltv_final;
1664 inv->invoice_blindedpay[0]->htlc_minimum_msat = AMOUNT_MSAT(0);
1665 inv->invoice_blindedpay[0]->htlc_maximum_msat = AMOUNT_MSAT(21000000 * MSAT_PER_BTC);
1666 inv->invoice_blindedpay[0]->features = NULL;
1667
1668 /* Recalc ->fields */
1669 tlv_update_fields(inv, tlv_invoice, &inv->fields);
1670}
1671
1672static struct command_result *json_createinvoice(struct command *cmd,
1673 const char *buffer,

Callers 1

json_createinvoiceFunction · 0.85

Calls 5

pubkey_from_privkeyFunction · 0.85
abortFunction · 0.85
bolt12_path_idFunction · 0.85

Tested by

no test coverage detected