diff --git a/bitcoin/script.c b/bitcoin/script.c index 397aab536..675340471 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -182,17 +182,23 @@ u8 *bitcoin_redeem_2of2(const tal_t *ctx, return script; } +u8 *scriptpubkey_p2sh_hash(const tal_t *ctx, const struct ripemd160 *redeemhash) +{ + u8 *script = tal_arr(ctx, u8, 0); + + add_op(&script, OP_HASH160); + add_push_bytes(&script, redeemhash->u.u8, sizeof(redeemhash->u.u8)); + add_op(&script, OP_EQUAL); + return script; +} + /* Create p2sh for this redeem script. */ u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript) { struct ripemd160 redeemhash; - u8 *script = tal_arr(ctx, u8, 0); - add_op(&script, OP_HASH160); hash160(&redeemhash, redeemscript, tal_count(redeemscript)); - add_push_bytes(&script, redeemhash.u.u8, sizeof(redeemhash.u.u8)); - add_op(&script, OP_EQUAL); - return script; + return scriptpubkey_p2sh_hash(ctx, &redeemhash); } /* Create an output script using p2pkh */ diff --git a/bitcoin/script.h b/bitcoin/script.h index 8a11783d8..5752bc9f6 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -23,6 +23,9 @@ u8 *bitcoin_redeem_2of2(const tal_t *ctx, /* Create an output script using p2sh for this redeem script. */ u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript); +/* Create an output script using p2sh for this hash. */ +u8 *scriptpubkey_p2sh_hash(const tal_t *ctx, const struct ripemd160 *redeemhash); + /* Create an output script using p2pkh */ u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr);