From 91bfe6954dfeb36a4a723d1ad0c3fa6b5e2a15a7 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 1 Feb 2021 21:26:14 -0500 Subject: [PATCH] python: Raise ValueError for non-existant tx hashes If the device asks for a tx_hash which is not present in prev_txes, raise a ValueError with some more detailed messaging about the missing hash rather than the default dictionary lookup failure of KeyError. --- python/src/trezorlib/btc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 775dcf76784..2a691b6cd20 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -279,6 +279,8 @@ def copy_tx_meta(tx: messages.TransactionType) -> messages.TransactionType: # Device asked for one more information, let's process it. if res.details.tx_hash is not None: + if res.details.tx_hash not in prev_txes: + raise ValueError(f"Previous transaction {res.details.tx_hash.hex()} not available") current_tx = prev_txes[res.details.tx_hash] else: current_tx = this_tx