Browse Source

bitcoin/script: rename bitcoin_redeem_p2wpkh -> bitcoin_redeem_p2sh_p2wpkh

This is its full name, and less confusing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
39993f229d
  1. 13
      bitcoin/script.c
  2. 5
      bitcoin/script.h
  3. 6
      daemon/wallet.c
  4. 2
      lightningd/build_utxos.c
  5. 2
      lightningd/hsm/hsm.c

13
bitcoin/script.c

@ -244,7 +244,7 @@ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
} }
/* Create the redeemscript for a P2SH + P2WPKH (for signing tx) */ /* Create the redeemscript for a P2SH + P2WPKH (for signing tx) */
u8 *bitcoin_redeem_p2wpkh(const tal_t *ctx, const struct pubkey *key) u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key)
{ {
struct ripemd160 keyhash; struct ripemd160 keyhash;
u8 der[PUBKEY_DER_LEN]; u8 der[PUBKEY_DER_LEN];
@ -261,7 +261,7 @@ u8 *bitcoin_redeem_p2wpkh(const tal_t *ctx, const struct pubkey *key)
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)
{ {
u8 *redeemscript = bitcoin_redeem_p2wpkh(ctx, key), *script; u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(ctx, key), *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. */
@ -277,7 +277,7 @@ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
const secp256k1_ecdsa_signature *sig, const secp256k1_ecdsa_signature *sig,
const struct pubkey *key) const struct pubkey *key)
{ {
u8 *redeemscript = bitcoin_redeem_p2wpkh(ctx, key); u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(ctx, key);
/* BIP141: The scriptSig must be exactly a push of the BIP16 redeemScript /* BIP141: The scriptSig must be exactly a push of the BIP16 redeemScript
* or validation fails. */ * or validation fails. */
@ -285,12 +285,7 @@ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
add_push_bytes(&input->script, redeemscript, tal_count(redeemscript)); add_push_bytes(&input->script, redeemscript, tal_count(redeemscript));
tal_free(redeemscript); tal_free(redeemscript);
/* BIP141: The witness must consist of exactly 2 items (≤ 520 input->witness = bitcoin_witness_p2wpkh(ctx, sig, key);
* bytes each). The first one a signature, and the second one
* a public key. */
input->witness = tal_arr(ctx, u8 *, 2);
input->witness[0] = stack_sig(input->witness, sig);
input->witness[1] = stack_key(input->witness, key);
} }
u8 **bitcoin_witness_p2wpkh(const tal_t *ctx, u8 **bitcoin_witness_p2wpkh(const tal_t *ctx,

5
bitcoin/script.h

@ -42,10 +42,9 @@ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
const secp256k1_ecdsa_signature *sig); const secp256k1_ecdsa_signature *sig);
/* Create the redeemscript for a P2SH + P2WPKH. */ /* Create the redeemscript for a P2SH + P2WPKH. */
u8 *bitcoin_redeem_p2wpkh(const tal_t *ctx, u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key);
const struct pubkey *key);
/* Create a witness which spends the 2of2. */ /* Create a witness which spends the P2SH + P2WPKH. */
void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx, void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
struct bitcoin_tx_input *input, struct bitcoin_tx_input *input,
const secp256k1_ecdsa_signature *sig, const secp256k1_ecdsa_signature *sig,

6
daemon/wallet.c

@ -33,7 +33,7 @@ bool restore_wallet_address(struct lightningd_state *dstate,
if (!pubkey_from_privkey(&w->privkey, &w->pubkey)) if (!pubkey_from_privkey(&w->privkey, &w->pubkey))
return false; return false;
redeemscript = bitcoin_redeem_p2wpkh(w, &w->pubkey); redeemscript = bitcoin_redeem_p2sh_p2wpkh(w, &w->pubkey);
sha256(&h, redeemscript, tal_count(redeemscript)); sha256(&h, redeemscript, tal_count(redeemscript));
ripemd160(&w->p2sh, h.u.u8, sizeof(h)); ripemd160(&w->p2sh, h.u.u8, sizeof(h));
@ -74,7 +74,7 @@ bool wallet_add_signed_input(struct lightningd_state *dstate,
if (!w) if (!w)
return false; return false;
redeemscript = bitcoin_redeem_p2wpkh(tx, &w->pubkey); redeemscript = bitcoin_redeem_p2sh_p2wpkh(tx, &w->pubkey);
sign_tx_input(tx, input_num, sign_tx_input(tx, input_num,
redeemscript, redeemscript,
@ -120,7 +120,7 @@ static void json_newaddr(struct command *cmd,
struct sha256 h; struct sha256 h;
new_keypair(&w->privkey, &w->pubkey); new_keypair(&w->privkey, &w->pubkey);
redeemscript = bitcoin_redeem_p2wpkh(cmd, &w->pubkey); redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &w->pubkey);
sha256(&h, redeemscript, tal_count(redeemscript)); sha256(&h, redeemscript, tal_count(redeemscript));
ripemd160(&w->p2sh, h.u.u8, sizeof(h)); ripemd160(&w->p2sh, h.u.u8, sizeof(h));

2
lightningd/build_utxos.c

@ -44,7 +44,7 @@ static void json_newaddr(struct command *cmd,
return; return;
} }
redeemscript = bitcoin_redeem_p2wpkh(cmd, &pubkey); redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey);
sha256(&h, redeemscript, tal_count(redeemscript)); sha256(&h, redeemscript, tal_count(redeemscript));
ripemd160(&p2sh, h.u.u8, sizeof(h)); ripemd160(&p2sh, h.u.u8, sizeof(h));

2
lightningd/hsm/hsm.c

@ -399,7 +399,7 @@ static u8 *sign_funding_tx(const tal_t *ctx, const u8 *data)
bitcoin_keypair(&inprivkey, &inkey, in->keyindex); bitcoin_keypair(&inprivkey, &inkey, in->keyindex);
if (in->is_p2sh) if (in->is_p2sh)
subscript = bitcoin_redeem_p2wpkh(tmpctx, &inkey); subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey);
else else
subscript = NULL; subscript = NULL;
wscript = p2wpkh_scriptcode(tmpctx, &inkey); wscript = p2wpkh_scriptcode(tmpctx, &inkey);

Loading…
Cancel
Save