mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 14:58:09 +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.
|
# 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 coins, messages
|
from . import messages
|
||||||
from .tools import CallException, expect, normalize_nfc, session
|
from .tools import CallException, expect, normalize_nfc, session
|
||||||
|
|
||||||
|
|
||||||
@ -88,27 +88,7 @@ def verify_message(client, coin_name, address, signature, message):
|
|||||||
|
|
||||||
@session
|
@session
|
||||||
def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
|
def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
|
||||||
# set up a transactions dict
|
this_tx = messages.TransactionType(inputs=inputs, outputs=outputs)
|
||||||
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
|
|
||||||
|
|
||||||
if details is None:
|
if details is None:
|
||||||
signtx = messages.SignTx()
|
signtx = messages.SignTx()
|
||||||
@ -155,7 +135,10 @@ def sign_tx(client, coin_name, inputs, outputs, details=None, prev_txes=None):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Device asked for one more information, let's process it.
|
# 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:
|
if res.request_type == R.TXMETA:
|
||||||
msg = copy_tx_meta(current_tx)
|
msg = copy_tx_meta(current_tx)
|
||||||
|
Loading…
Reference in New Issue
Block a user