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

Function encode_scriptpubkey_to_addr

common/addr.c:8–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <common/bech32.h>
7
8char *encode_scriptpubkey_to_addr(const tal_t *ctx,
9 const struct chainparams *chainparams,
10 const u8 *scriptpubkey,
11 size_t scriptpubkey_len)
12{
13 char *out;
14 struct bitcoin_address pkh;
15 struct ripemd160 sh;
16 int witver;
17
18 if (is_p2pkh(scriptpubkey, scriptpubkey_len, &pkh))
19 return bitcoin_to_base58(ctx, chainparams, &pkh);
20
21 if (is_p2sh(scriptpubkey, scriptpubkey_len, &sh))
22 return p2sh_to_base58(ctx, chainparams, &sh);
23
24 if (is_p2tr(scriptpubkey, scriptpubkey_len, NULL))
25 witver = 1;
26 else if (is_p2wpkh(scriptpubkey, scriptpubkey_len, NULL)
27 || is_p2wsh(scriptpubkey, scriptpubkey_len, NULL))
28 witver = 0;
29 else {
30 return NULL;
31 }
32 out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
33 if (!segwit_addr_encode(out, chainparams->onchain_hrp, witver,
34 scriptpubkey + 2, scriptpubkey_len - 2))
35 return tal_free(out);
36
37 return out;
38}
39
40static const char *segwit_addr_net_decode(int *witness_version,
41 uint8_t *witness_program,

Callers 9

json_listaddressesFunction · 0.85
json_add_utxoFunction · 0.85
json_signmessagewithkeyFunction · 0.85
NON_NULL_ARGSFunction · 0.85
watch_check_tx_outputsFunction · 0.85
funding_started_successFunction · 0.85
runFunction · 0.85
json_add_fallbackFunction · 0.85
execute_spliceFunction · 0.85

Calls 9

bitcoin_to_base58Function · 0.85
p2sh_to_base58Function · 0.85
is_p2wpkhFunction · 0.85
is_p2wshFunction · 0.85
segwit_addr_encodeFunction · 0.85
tal_freeFunction · 0.85
is_p2pkhFunction · 0.50
is_p2shFunction · 0.50
is_p2trFunction · 0.50

Tested by

no test coverage detected