Browse Source

script: break out redeemscript->scriptsig function

We're going to finalze some redeemscripts here shortly, so break out the
ability to render an arbitrary redeemscript -> scriptsig
travis-experimental
niftynei 4 years ago
committed by Rusty Russell
parent
commit
0ca6c3cc84
  1. 18
      bitcoin/script.c
  2. 4
      bitcoin/script.h

18
bitcoin/script.c

@ -261,18 +261,30 @@ u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key)
return script; return script;
} }
u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key) u8 *bitcoin_scriptsig_redeem(const tal_t *ctx,
const u8 *redeemscript TAKES)
{ {
u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(ctx, key), *script; u8 *script;
/* BIP141: The scriptSig must be exactly a push of the BIP16 /* BIP141: The scriptSig must be exactly a push of the BIP16
* redeemScript or validation fails. */ * redeemScript or validation fails. */
script = tal_arr(ctx, u8, 0); script = tal_arr(ctx, u8, 0);
script_push_bytes(&script, redeemscript, tal_count(redeemscript)); script_push_bytes(&script, redeemscript,
tal_count(redeemscript));
if (taken(redeemscript))
tal_free(redeemscript); tal_free(redeemscript);
return script; return script;
} }
u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key)
{
u8 *redeemscript =
bitcoin_redeem_p2sh_p2wpkh(NULL, key);
return bitcoin_scriptsig_redeem(ctx, take(redeemscript));
}
u8 **bitcoin_witness_p2wpkh(const tal_t *ctx, u8 **bitcoin_witness_p2wpkh(const tal_t *ctx,
const struct bitcoin_signature *sig, const struct bitcoin_signature *sig,
const struct pubkey *key) const struct pubkey *key)

4
bitcoin/script.h

@ -43,6 +43,10 @@ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
/* Create the redeemscript for a P2SH + P2WPKH. */ /* Create the redeemscript for a P2SH + P2WPKH. */
u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key); u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key);
/* Create the scriptsig for a redeemscript */
u8 *bitcoin_scriptsig_redeem(const tal_t *ctx,
const u8 *redeemscript TAKES);
/* Create scriptsig for p2sh-p2wpkh */ /* Create scriptsig for p2sh-p2wpkh */
u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key); u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key);

Loading…
Cancel
Save