mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
script: add p2sh scriptpubkey helper to create from hash.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -182,17 +182,23 @@ u8 *bitcoin_redeem_2of2(const tal_t *ctx,
|
|||||||
return script;
|
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. */
|
/* Create p2sh for this redeem script. */
|
||||||
u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript)
|
u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript)
|
||||||
{
|
{
|
||||||
struct ripemd160 redeemhash;
|
struct ripemd160 redeemhash;
|
||||||
u8 *script = tal_arr(ctx, u8, 0);
|
|
||||||
|
|
||||||
add_op(&script, OP_HASH160);
|
|
||||||
hash160(&redeemhash, redeemscript, tal_count(redeemscript));
|
hash160(&redeemhash, redeemscript, tal_count(redeemscript));
|
||||||
add_push_bytes(&script, redeemhash.u.u8, sizeof(redeemhash.u.u8));
|
return scriptpubkey_p2sh_hash(ctx, &redeemhash);
|
||||||
add_op(&script, OP_EQUAL);
|
|
||||||
return script;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an output script using p2pkh */
|
/* Create an output script using p2pkh */
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ u8 *bitcoin_redeem_2of2(const tal_t *ctx,
|
|||||||
/* Create an output script using p2sh for this redeem script. */
|
/* Create an output script using p2sh for this redeem script. */
|
||||||
u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript);
|
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 */
|
/* Create an output script using p2pkh */
|
||||||
u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr);
|
u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user