fallback: json add fallback cleanup

Expand to handle P2TR addresses, use the common script encoding utility
function instead of reimplementing it.
This commit is contained in:
niftynei 2023-10-26 14:02:08 +10:30 committed by Rusty Russell
parent 44798e298c
commit 411bb2884a
10 changed files with 153 additions and 157 deletions

View File

@ -38,6 +38,7 @@
"DecodepayFallbacksType": {
"P2PKH": 0,
"P2SH": 1,
"P2TR": 4,
"P2WPKH": 2,
"P2WSH": 3
},

Binary file not shown.

BIN
cln-rpc/src/model.rs generated

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include <bitcoin/base58.h>
#include <bitcoin/script.h>
#include <ccan/tal/str/str.h>
#include <common/addr.h>
#include <common/bech32.h>
#include <common/bolt11.h>
#include <common/bolt11_json.h>
@ -13,32 +14,24 @@ static void json_add_fallback(struct json_stream *response,
const u8 *fallback,
const struct chainparams *chain)
{
struct bitcoin_address pkh;
struct ripemd160 sh;
struct sha256 wsh;
char *addr;
json_object_start(response, fieldname);
if (is_p2pkh(fallback, &pkh)) {
if (is_p2pkh(fallback, NULL)) {
json_add_string(response, "type", "P2PKH");
json_add_string(response, "addr",
bitcoin_to_base58(tmpctx, chain, &pkh));
} else if (is_p2sh(fallback, &sh)) {
} else if (is_p2sh(fallback, NULL)) {
json_add_string(response, "type", "P2SH");
json_add_string(response, "addr",
p2sh_to_base58(tmpctx, chain, &sh));
} else if (is_p2wpkh(fallback, &pkh)) {
char out[73 + strlen(chain->onchain_hrp)];
} else if (is_p2wpkh(fallback, NULL)) {
json_add_string(response, "type", "P2WPKH");
if (segwit_addr_encode(out, chain->onchain_hrp, 0,
(const u8 *)&pkh, sizeof(pkh)))
json_add_string(response, "addr", out);
} else if (is_p2wsh(fallback, &wsh)) {
char out[73 + strlen(chain->onchain_hrp)];
} else if (is_p2wsh(fallback, NULL)) {
json_add_string(response, "type", "P2WSH");
if (segwit_addr_encode(out, chain->onchain_hrp, 0,
(const u8 *)&wsh, sizeof(wsh)))
json_add_string(response, "addr", out);
} else if (is_p2tr(fallback, NULL)) {
json_add_string(response, "type", "P2TR");
}
addr = encode_scriptpubkey_to_addr(tmpctx, chain, fallback);
if (addr)
json_add_string(response, "addr", addr);
json_add_hex_talarr(response, "hex", fallback);
json_object_end(response);
}

File diff suppressed because one or more lines are too long

View File

@ -249,7 +249,7 @@ If **type** is "bolt11 invoice", and **valid** is *true*:
- **features** (hex, optional): the features bitmap for this invoice
- **payment\_metadata** (hex, optional): the payment\_metadata to put in the payment
- **fallbacks** (array of objects, optional): onchain addresses:
- **type** (string): the address type (if known) (one of "P2PKH", "P2SH", "P2WPKH", "P2WSH")
- **type** (string): the address type (if known) (one of "P2PKH", "P2SH", "P2WPKH", "P2WSH", "P2TR")
- **hex** (hex): Raw encoded address
- **addr** (string, optional): the address in appropriate format for *type*
- **routes** (array of arrays, optional): Route hints to the *payee*:
@ -303,4 +303,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:2f77622e54345ebdffbbc0823f73c8f709a29de536be0c84290aac65e5405d3a)
[comment]: # ( SHA256STAMP:ee1667eb4bf5eda980615dbcee334f618991e4b648a07ded8868ecde09bb2554)

View File

@ -32,7 +32,7 @@ On success, an object is returned, containing:
- **features** (hex, optional): the features bitmap for this invoice
- **payment\_metadata** (hex, optional): the payment\_metadata to put in the payment
- **fallbacks** (array of objects, optional): onchain addresses:
- **type** (string): the address type (if known) (one of "P2PKH", "P2SH", "P2WPKH", "P2WSH")
- **type** (string): the address type (if known) (one of "P2PKH", "P2SH", "P2WPKH", "P2WSH", "P2TR")
- **hex** (hex): Raw encoded address
- **addr** (string, optional): the address in appropriate format for *type*
- **routes** (array of arrays, optional): Route hints to the *payee*:
@ -71,4 +71,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:e20f638716d74697afbea9cb4dd5afa380505dda65dcd3bba1579d2ed79bdc6b)
[comment]: # ( SHA256STAMP:14c7dd565178078d7073e2837ad283a1e811affb5017e72c69e69d9f8c2baabd)

View File

@ -1313,7 +1313,8 @@
"P2PKH",
"P2SH",
"P2WPKH",
"P2WSH"
"P2WSH",
"P2TR"
]
},
"addr": {

View File

@ -82,7 +82,8 @@
"P2PKH",
"P2SH",
"P2WPKH",
"P2WSH"
"P2WSH",
"P2TR"
]
},
"addr": {

View File

@ -209,7 +209,7 @@ $(PLUGIN_KEYSEND_OBJS): $(PLUGIN_PAY_LIB_HEADER)
plugins/spenderp: bitcoin/block.o bitcoin/preimage.o bitcoin/psbt.o common/psbt_open.o wire/peer${EXP}_wiregen.o $(PLUGIN_SPENDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS)
plugins/offers: $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o common/blindedpath.o common/invoice_path_id.o common/blinding.o common/hmac.o $(JSMN_OBJS)
plugins/offers: $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/addr.o common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o common/blindedpath.o common/invoice_path_id.o common/blinding.o common/hmac.o $(JSMN_OBJS)
plugins/fetchinvoice: $(PLUGIN_FETCHINVOICE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/iso4217.o $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o $(JSMN_OBJS) common/gossmap.o common/fp16.o common/dijkstra.o common/route.o common/blindedpath.o common/hmac.o common/blinding.o