script: consistently take the script length in identification functions
Standardizes the is_xxx script function all take a script length, and changes their first-level callers to pass it. This has several knock on benefits: - We remove the repeated tal_count/tal_bytelen calls on the script, in particular the redundant calls that result when we must check for multiple types of script - which is almost all cases. - We remove the dependency on the memory being tal-allocated (It is, in all cases, but theres no reason we need to require that). - We remove all cases where we create a copy of the script just to id it. - We remove all allocations for non-interesting scripts while iterating block txs in process_getfilteredblock_step1(). - We remove all allocations *including for potentially interesting scripts* in topo_add_utxos(). Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
This commit is contained in:
committed by
Rusty Russell
parent
5dee5ce178
commit
aa23c2a2b2
@@ -123,23 +123,25 @@ int main(int argc, char *argv[])
|
||||
struct bitcoin_address pkh;
|
||||
struct ripemd160 sh;
|
||||
struct sha256 wsh;
|
||||
const u8 *fallback = b11->fallbacks[i];
|
||||
const size_t fallback_len = tal_bytelen(fallback);
|
||||
|
||||
printf("fallback: %s\n", tal_hex(ctx, b11->fallbacks[i]));
|
||||
if (is_p2pkh(b11->fallbacks[i], &pkh)) {
|
||||
printf("fallback: %s\n", tal_hex(ctx, fallback));
|
||||
if (is_p2pkh(fallback, fallback_len, &pkh)) {
|
||||
printf("fallback-P2PKH: %s\n",
|
||||
bitcoin_to_base58(ctx, b11->chain,
|
||||
&pkh));
|
||||
} else if (is_p2sh(b11->fallbacks[i], &sh)) {
|
||||
} else if (is_p2sh(fallback, fallback_len, &sh)) {
|
||||
printf("fallback-P2SH: %s\n",
|
||||
p2sh_to_base58(ctx,
|
||||
b11->chain,
|
||||
&sh));
|
||||
} else if (is_p2wpkh(b11->fallbacks[i], &pkh)) {
|
||||
} else if (is_p2wpkh(fallback, fallback_len, &pkh)) {
|
||||
char out[73 + strlen(b11->chain->onchain_hrp)];
|
||||
if (segwit_addr_encode(out, b11->chain->onchain_hrp, 0,
|
||||
(const u8 *)&pkh, sizeof(pkh)))
|
||||
printf("fallback-P2WPKH: %s\n", out);
|
||||
} else if (is_p2wsh(b11->fallbacks[i], &wsh)) {
|
||||
} else if (is_p2wsh(fallback, fallback_len, &wsh)) {
|
||||
char out[73 + strlen(b11->chain->onchain_hrp)];
|
||||
if (segwit_addr_encode(out, b11->chain->onchain_hrp, 0,
|
||||
(const u8 *)&wsh, sizeof(wsh)))
|
||||
|
||||
Reference in New Issue
Block a user