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

Function add_stub_blindedpath

lightningd/invoice.c:1606–1657  ·  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

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