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

Function encode_scriptpubkey_to_addr

common/addr.c:8–29  ·  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{
12 char *out;
13 size_t scriptLen = tal_bytelen(scriptPubkey);
14 struct bitcoin_address pkh;
15 struct ripemd160 sh;
16
17 if (is_p2pkh(scriptPubkey, &pkh))
18 return bitcoin_to_base58(ctx, chainparams, &pkh);
19
20 if (is_p2sh(scriptPubkey, &sh))
21 return p2sh_to_base58(ctx, chainparams, &sh);
22
23 out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
24 if (!segwit_addr_encode(out, chainparams->onchain_hrp, 0,
25 scriptPubkey + 2, scriptLen - 2))
26 return tal_free(out);
27
28 return out;
29}

Callers 1

runFunction · 0.50

Calls 7

tal_bytelenFunction · 0.85
bitcoin_to_base58Function · 0.85
p2sh_to_base58Function · 0.85
segwit_addr_encodeFunction · 0.85
tal_freeFunction · 0.85
is_p2pkhFunction · 0.50
is_p2shFunction · 0.50

Tested by

no test coverage detected