1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-22 05:10:56 +00:00

Don't require prevtx for coins with BIP-143 fork id (#352)

Coins like Bitcoin Cash and Bitcoin Gold always use BIP-143 signatures
that do not require previous transactions.
This commit is contained in:
Jochen Hoenicke 2019-01-07 12:57:12 +01:00 committed by matejcik
parent 369b704f6b
commit 0428f5091c

View File

@ -14,7 +14,7 @@
# You should have received a copy of the License along with this library. # You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from . import messages from . import coins, messages
from .tools import CallException, expect, normalize_nfc, session from .tools import CallException, expect, normalize_nfc, session
@ -91,19 +91,24 @@ def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
# set up a transactions dict # set up a transactions dict
txes = {None: messages.TransactionType(inputs=inputs, outputs=outputs)} txes = {None: messages.TransactionType(inputs=inputs, outputs=outputs)}
# preload all relevant transactions ahead of time # preload all relevant transactions ahead of time
for inp in inputs: if coin_name in coins.by_name:
if inp.script_type not in ( load_prevtxes = not coins.by_name[coin_name]["force_bip143"]
messages.InputScriptType.SPENDP2SHWITNESS, else:
messages.InputScriptType.SPENDWITNESS, load_prevtxes = True
messages.InputScriptType.EXTERNAL, if load_prevtxes:
): for inp in inputs:
try: if inp.script_type not in (
prev_tx = prev_txes[inp.prev_hash] messages.InputScriptType.SPENDP2SHWITNESS,
except Exception as e: messages.InputScriptType.SPENDWITNESS,
raise ValueError("Could not retrieve prev_tx") from e messages.InputScriptType.EXTERNAL,
if not isinstance(prev_tx, messages.TransactionType): ):
raise ValueError("Invalid value for prev_tx") from None try:
txes[inp.prev_hash] = prev_tx prev_tx = prev_txes[inp.prev_hash]
except Exception as e:
raise ValueError("Could not retrieve prev_tx") from e
if not isinstance(prev_tx, messages.TransactionType):
raise ValueError("Invalid value for prev_tx") from None
txes[inp.prev_hash] = prev_tx
if details is None: if details is None:
signtx = messages.SignTx() signtx = messages.SignTx()