Skip to content

Commit

Permalink
addr: avoid a redundant allocation for unknown script types
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
  • Loading branch information
jgriffiths authored and rustyrussell committed Mar 18, 2024
1 parent 4055393 commit 3f678ad
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx,
if (is_p2sh(scriptpubkey, script_len, &sh))
return p2sh_to_base58(ctx, chainparams, &sh);

out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
if (is_p2tr(scriptpubkey, script_len, NULL))
witver = 1;
else if (is_p2wpkh(scriptpubkey, script_len, NULL)
|| is_p2wsh(scriptpubkey, script_len, NULL))
witver = 0;
else {
return tal_free(out);
return NULL;
}
out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
if (!segwit_addr_encode(out, chainparams->onchain_hrp, witver,
scriptpubkey + 2, script_len - 2))
return tal_free(out);
Expand Down

0 comments on commit 3f678ad

Please sign in to comment.