mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
encode_scriptpubkey_to_addr: support p2tr
This commit is contained in:
parent
3c689cdaff
commit
fa046ab80f
@ -13,6 +13,7 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx,
|
||||
size_t scriptLen = tal_bytelen(scriptPubkey);
|
||||
struct bitcoin_address pkh;
|
||||
struct ripemd160 sh;
|
||||
int witver;
|
||||
|
||||
if (is_p2pkh(scriptPubkey, &pkh))
|
||||
return bitcoin_to_base58(ctx, chainparams, &pkh);
|
||||
@ -21,7 +22,14 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx,
|
||||
return p2sh_to_base58(ctx, chainparams, &sh);
|
||||
|
||||
out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
|
||||
if (!segwit_addr_encode(out, chainparams->onchain_hrp, 0,
|
||||
if (is_p2tr(scriptPubkey, NULL))
|
||||
witver = 1;
|
||||
else if (is_p2wpkh(scriptPubkey, NULL) || is_p2wsh(scriptPubkey, NULL))
|
||||
witver = 0;
|
||||
else {
|
||||
return tal_free(out);
|
||||
}
|
||||
if (!segwit_addr_encode(out, chainparams->onchain_hrp, witver,
|
||||
scriptPubkey + 2, scriptLen - 2))
|
||||
return tal_free(out);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/chainparams.h>
|
||||
|
||||
/* Given a scriptPubkey, return an encoded address */
|
||||
/* Given a scriptPubkey, return an encoded address for p2pkh/p2w{pkh,sh}/p2tr */
|
||||
char *encode_scriptpubkey_to_addr(const tal_t *ctx,
|
||||
const struct chainparams *chainparams,
|
||||
const u8 *scriptPubkey);
|
||||
|
Loading…
Reference in New Issue
Block a user