mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 09:04:25 +01:00
BOLT 12: switch invoice_request/invoice to singular chain field.
We keep the now-removed chains field, and in deprecated mode, we set it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-EXPERIMENTAL: bolt12: `chains` in invoice_request and invoice is deprecated, `chain` is used instead.
This commit is contained in:
committed by
Christian Decker
parent
45bf7a3974
commit
c92ce59892
@@ -1395,8 +1395,12 @@ static struct command_result *json_fetchinvoice(struct command *cmd,
|
||||
* - the bitcoin chain is implied as the first and only entry.
|
||||
*/
|
||||
if (!streq(chainparams->network_name, "bitcoin")) {
|
||||
invreq->chains = tal_arr(invreq, struct bitcoin_blkid, 1);
|
||||
invreq->chains[0] = chainparams->genesis_blockhash;
|
||||
if (deprecated_apis) {
|
||||
invreq->chains = tal_arr(invreq, struct bitcoin_blkid, 1);
|
||||
invreq->chains[0] = chainparams->genesis_blockhash;
|
||||
}
|
||||
invreq->chain = tal_dup(invreq, struct bitcoin_blkid,
|
||||
&chainparams->genesis_blockhash);
|
||||
}
|
||||
|
||||
invreq->features
|
||||
@@ -1790,8 +1794,12 @@ static struct command_result *json_sendinvoice(struct command *cmd,
|
||||
* - the bitcoin chain is implied as the first and only entry.
|
||||
*/
|
||||
if (!streq(chainparams->network_name, "bitcoin")) {
|
||||
sent->inv->chains = tal_arr(sent->inv, struct bitcoin_blkid, 1);
|
||||
sent->inv->chains[0] = chainparams->genesis_blockhash;
|
||||
if (deprecated_apis) {
|
||||
sent->inv->chains = tal_arr(sent->inv, struct bitcoin_blkid, 1);
|
||||
sent->inv->chains[0] = chainparams->genesis_blockhash;
|
||||
}
|
||||
sent->inv->chain = tal_dup(sent->inv, struct bitcoin_blkid,
|
||||
&chainparams->genesis_blockhash);
|
||||
}
|
||||
|
||||
sent->inv->features
|
||||
|
||||
@@ -565,6 +565,8 @@ static void json_add_b12_invoice(struct json_stream *js,
|
||||
|
||||
if (invoice->chains)
|
||||
json_add_chains(js, invoice->chains);
|
||||
if (invoice->chain)
|
||||
json_add_sha256(js, "chain", &invoice->chain->shad.sha);
|
||||
if (invoice->offer_id)
|
||||
json_add_sha256(js, "offer_id", invoice->offer_id);
|
||||
|
||||
@@ -700,7 +702,8 @@ static void json_add_b12_invoice(struct json_stream *js,
|
||||
json_add_u32(js, "min_final_cltv_expiry", 18);
|
||||
|
||||
if (invoice->fallbacks)
|
||||
valid &= json_add_fallbacks(js, invoice->chains,
|
||||
valid &= json_add_fallbacks(js,
|
||||
invoice->chain ? invoice->chain : invoice->chains,
|
||||
invoice->fallbacks->fallbacks);
|
||||
|
||||
/* BOLT-offers #12:
|
||||
@@ -749,6 +752,9 @@ static void json_add_invoice_request(struct json_stream *js,
|
||||
|
||||
if (invreq->chains)
|
||||
json_add_chains(js, invreq->chains);
|
||||
if (invreq->chain)
|
||||
json_add_sha256(js, "chain", &invreq->chain->shad.sha);
|
||||
|
||||
/* BOLT-offers #12:
|
||||
* - MUST fail the request if `payer_key` is not present.
|
||||
* - MUST fail the request if `chains` does not include (or imply) a supported chain.
|
||||
|
||||
@@ -369,10 +369,10 @@ struct command_result *handle_invoice(struct command *cmd,
|
||||
* - MUST fail the request if `chains` does not include (or imply) a
|
||||
* supported chain.
|
||||
*/
|
||||
if (!bolt12_chains_match(inv->inv->chains, chainparams)) {
|
||||
if (!bolt12_chain_matches(inv->inv->chain, chainparams, inv->inv->chains)) {
|
||||
return fail_inv(cmd, inv,
|
||||
"Wrong chains %s",
|
||||
tal_hex(tmpctx, inv->inv->chains));
|
||||
tal_hex(tmpctx, inv->inv->chain));
|
||||
}
|
||||
|
||||
/* BOLT-offers #12:
|
||||
|
||||
@@ -758,9 +758,14 @@ static struct command_result *listoffers_done(struct command *cmd,
|
||||
* - MUST specify `chains` the offer is valid for.
|
||||
*/
|
||||
if (!streq(chainparams->network_name, "bitcoin")) {
|
||||
ir->inv->chains = tal_arr(ir->inv, struct bitcoin_blkid, 1);
|
||||
ir->inv->chains[0] = chainparams->genesis_blockhash;
|
||||
if (deprecated_apis) {
|
||||
ir->inv->chains = tal_arr(ir->inv, struct bitcoin_blkid, 1);
|
||||
ir->inv->chains[0] = chainparams->genesis_blockhash;
|
||||
}
|
||||
ir->inv->chain = tal_dup(ir->inv, struct bitcoin_blkid,
|
||||
&chainparams->genesis_blockhash);
|
||||
}
|
||||
|
||||
/* BOLT-offers #12:
|
||||
* - MUST set `offer_id` to the id of the offer.
|
||||
*/
|
||||
@@ -883,10 +888,11 @@ struct command_result *handle_invoice_request(struct command *cmd,
|
||||
* - MUST fail the request if `chains` does not include (or imply) a
|
||||
* supported chain.
|
||||
*/
|
||||
if (!bolt12_chains_match(ir->invreq->chains, chainparams)) {
|
||||
if (!bolt12_chain_matches(ir->invreq->chain, chainparams,
|
||||
ir->invreq->chains)) {
|
||||
return fail_invreq(cmd, ir,
|
||||
"Wrong chains %s",
|
||||
tal_hex(tmpctx, ir->invreq->chains));
|
||||
"Wrong chain %s",
|
||||
tal_hex(tmpctx, ir->invreq->chain));
|
||||
}
|
||||
|
||||
/* BOLT-offers #12:
|
||||
|
||||
Reference in New Issue
Block a user