From 39993f229da795ae12da18a99484bc4662b307d9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 7 Mar 2017 11:35:48 +1030 Subject: [PATCH] bitcoin/script: rename bitcoin_redeem_p2wpkh -> bitcoin_redeem_p2sh_p2wpkh This is its full name, and less confusing. Signed-off-by: Rusty Russell --- bitcoin/script.c | 13 ++++--------- bitcoin/script.h | 5 ++--- daemon/wallet.c | 6 +++--- lightningd/build_utxos.c | 2 +- lightningd/hsm/hsm.c | 2 +- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/bitcoin/script.c b/bitcoin/script.c index d45d1e8cf..c0ce4dbc7 100644 --- a/bitcoin/script.c +++ b/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) */ -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; 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 *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 * redeemScript or validation fails. */ @@ -277,7 +277,7 @@ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx, const secp256k1_ecdsa_signature *sig, 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 * 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)); tal_free(redeemscript); - /* BIP141: The witness must consist of exactly 2 items (≤ 520 - * 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); + input->witness = bitcoin_witness_p2wpkh(ctx, sig, key); } u8 **bitcoin_witness_p2wpkh(const tal_t *ctx, diff --git a/bitcoin/script.h b/bitcoin/script.h index 6f10be179..dbb21a303 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -42,10 +42,9 @@ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey, const secp256k1_ecdsa_signature *sig); /* Create the redeemscript for a P2SH + P2WPKH. */ -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); -/* Create a witness which spends the 2of2. */ +/* Create a witness which spends the P2SH + P2WPKH. */ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx, struct bitcoin_tx_input *input, const secp256k1_ecdsa_signature *sig, diff --git a/daemon/wallet.c b/daemon/wallet.c index dfd0c32c6..8f33c6137 100644 --- a/daemon/wallet.c +++ b/daemon/wallet.c @@ -33,7 +33,7 @@ bool restore_wallet_address(struct lightningd_state *dstate, if (!pubkey_from_privkey(&w->privkey, &w->pubkey)) return false; - redeemscript = bitcoin_redeem_p2wpkh(w, &w->pubkey); + redeemscript = bitcoin_redeem_p2sh_p2wpkh(w, &w->pubkey); sha256(&h, redeemscript, tal_count(redeemscript)); ripemd160(&w->p2sh, h.u.u8, sizeof(h)); @@ -74,7 +74,7 @@ bool wallet_add_signed_input(struct lightningd_state *dstate, if (!w) return false; - redeemscript = bitcoin_redeem_p2wpkh(tx, &w->pubkey); + redeemscript = bitcoin_redeem_p2sh_p2wpkh(tx, &w->pubkey); sign_tx_input(tx, input_num, redeemscript, @@ -120,7 +120,7 @@ static void json_newaddr(struct command *cmd, struct sha256 h; 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)); ripemd160(&w->p2sh, h.u.u8, sizeof(h)); diff --git a/lightningd/build_utxos.c b/lightningd/build_utxos.c index a737e1175..cbcb0abb1 100644 --- a/lightningd/build_utxos.c +++ b/lightningd/build_utxos.c @@ -44,7 +44,7 @@ static void json_newaddr(struct command *cmd, return; } - redeemscript = bitcoin_redeem_p2wpkh(cmd, &pubkey); + redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey); sha256(&h, redeemscript, tal_count(redeemscript)); ripemd160(&p2sh, h.u.u8, sizeof(h)); diff --git a/lightningd/hsm/hsm.c b/lightningd/hsm/hsm.c index 8ce6c6677..3136aaa43 100644 --- a/lightningd/hsm/hsm.c +++ b/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); if (in->is_p2sh) - subscript = bitcoin_redeem_p2wpkh(tmpctx, &inkey); + subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey); else subscript = NULL; wscript = p2wpkh_scriptcode(tmpctx, &inkey);