mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
python: do not preload prev_txes, drop dependency on coins.json
This commit is contained in:
parent
75264a07a8
commit
37ea0773ea
@ -14,7 +14,7 @@
|
||||
# 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>.
|
||||
|
||||
from . import coins, messages
|
||||
from . import messages
|
||||
from .tools import CallException, expect, normalize_nfc, session
|
||||
|
||||
|
||||
@ -88,27 +88,7 @@ def verify_message(client, coin_name, address, signature, message):
|
||||
|
||||
@session
|
||||
def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
|
||||
# set up a transactions dict
|
||||
txes = {None: messages.TransactionType(inputs=inputs, outputs=outputs)}
|
||||
# preload all relevant transactions ahead of time
|
||||
if coin_name in coins.by_name:
|
||||
load_prevtxes = not coins.by_name[coin_name]["force_bip143"]
|
||||
else:
|
||||
load_prevtxes = True
|
||||
if load_prevtxes:
|
||||
for inp in inputs:
|
||||
if inp.script_type not in (
|
||||
messages.InputScriptType.SPENDP2SHWITNESS,
|
||||
messages.InputScriptType.SPENDWITNESS,
|
||||
messages.InputScriptType.EXTERNAL,
|
||||
):
|
||||
try:
|
||||
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
|
||||
this_tx = messages.TransactionType(inputs=inputs, outputs=outputs)
|
||||
|
||||
if details is None:
|
||||
signtx = messages.SignTx()
|
||||
@ -155,7 +135,10 @@ def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
|
||||
break
|
||||
|
||||
# Device asked for one more information, let's process it.
|
||||
current_tx = txes[res.details.tx_hash]
|
||||
if res.details.tx_hash is not None:
|
||||
current_tx = prev_txes[res.details.tx_hash]
|
||||
else:
|
||||
current_tx = this_tx
|
||||
|
||||
if res.request_type == R.TXMETA:
|
||||
msg = copy_tx_meta(current_tx)
|
||||
|
Loading…
Reference in New Issue
Block a user