From 173bb7ed13bef73e41a1f670481cbe13772e60d0 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Wed, 10 Jun 2020 11:43:48 +0200 Subject: [PATCH] core/bitcoin: Replace TxInputType parameter in input_derive_script. --- core/src/apps/bitcoin/scripts.py | 22 ++++++++++++---------- core/src/apps/bitcoin/sign_tx/bitcoin.py | 7 ++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/src/apps/bitcoin/scripts.py b/core/src/apps/bitcoin/scripts.py index 56ba8a125..02799a9ec 100644 --- a/core/src/apps/bitcoin/scripts.py +++ b/core/src/apps/bitcoin/scripts.py @@ -24,41 +24,43 @@ from .writers import ( if False: from typing import List, Optional + from trezor.messages.TxInputType import EnumTypeInputScriptType from .writers import Writer def input_derive_script( - txi: TxInputType, + script_type: EnumTypeInputScriptType, + multisig: MultisigRedeemScriptType, coin: CoinInfo, hash_type: int, pubkey: bytes, signature: Optional[bytes], ) -> bytes: - if txi.script_type == InputScriptType.SPENDADDRESS: + if script_type == InputScriptType.SPENDADDRESS: # p2pkh or p2sh return input_script_p2pkh_or_p2sh(pubkey, signature, hash_type) - if txi.script_type == InputScriptType.SPENDP2SHWITNESS: + if script_type == InputScriptType.SPENDP2SHWITNESS: # p2wpkh or p2wsh using p2sh - if txi.multisig: + if multisig: # p2wsh in p2sh - pubkeys = multisig_get_pubkeys(txi.multisig) + pubkeys = multisig_get_pubkeys(multisig) witness_script_hasher = utils.HashWriter(sha256()) - write_output_script_multisig(witness_script_hasher, pubkeys, txi.multisig.m) + write_output_script_multisig(witness_script_hasher, pubkeys, multisig.m) witness_script_hash = witness_script_hasher.get_digest() return input_script_p2wsh_in_p2sh(witness_script_hash) # p2wpkh in p2sh return input_script_p2wpkh_in_p2sh(common.ecdsa_hash_pubkey(pubkey, coin)) - elif txi.script_type == InputScriptType.SPENDWITNESS: + elif script_type == InputScriptType.SPENDWITNESS: # native p2wpkh or p2wsh return input_script_native_p2wpkh_or_p2wsh() - elif txi.script_type == InputScriptType.SPENDMULTISIG: + elif script_type == InputScriptType.SPENDMULTISIG: # p2sh multisig - signature_index = multisig_pubkey_index(txi.multisig, pubkey) + signature_index = multisig_pubkey_index(multisig, pubkey) return input_script_multisig( - txi.multisig, signature, signature_index, hash_type, coin + multisig, signature, signature_index, hash_type, coin ) else: raise wire.ProcessError("Invalid script type") diff --git a/core/src/apps/bitcoin/sign_tx/bitcoin.py b/core/src/apps/bitcoin/sign_tx/bitcoin.py index ca2571df0..d271c54de 100644 --- a/core/src/apps/bitcoin/sign_tx/bitcoin.py +++ b/core/src/apps/bitcoin/sign_tx/bitcoin.py @@ -467,7 +467,12 @@ class Bitcoin: self, txi: TxInputType, pubkey: bytes, signature: bytes = None ) -> bytes: return scripts.input_derive_script( - txi, self.coin, self.get_hash_type(), pubkey, signature + txi.script_type, + txi.multisig, + self.coin, + self.get_hash_type(), + pubkey, + signature, ) # BIP-0143