From 23a09fc0476ab130877e92ccefed6276e092f480 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 1 Feb 2021 21:26:14 -0500 Subject: [PATCH] feat(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/.changelog.d/1442.changed | 1 + python/src/trezorlib/btc.py | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 python/.changelog.d/1442.changed diff --git a/python/.changelog.d/1442.changed b/python/.changelog.d/1442.changed new file mode 100644 index 000000000..8da49b99e --- /dev/null +++ b/python/.changelog.d/1442.changed @@ -0,0 +1 @@ +Raise `ValueError` when the txid for an input is not present in `prev_txes` during `btc.sign_tx` diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index c8ae222e1..316e27be9 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -334,6 +334,10 @@ def sign_tx( # 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