mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
core: propagate coin info to all sanitize functions
This commit is contained in:
parent
303c05aba7
commit
136307bcae
@ -104,14 +104,14 @@ def confirm_nondefault_locktime(lock_time: int):
|
||||
return (yield UiConfirmNonDefaultLocktime(lock_time))
|
||||
|
||||
|
||||
def request_tx_meta(tx_req: TxRequest, tx_hash: bytes = None):
|
||||
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None):
|
||||
tx_req.request_type = TXMETA
|
||||
tx_req.details.tx_hash = tx_hash
|
||||
tx_req.details.request_index = None
|
||||
ack = yield tx_req
|
||||
tx_req.serialized = None
|
||||
gc.collect()
|
||||
return sanitize_tx_meta(ack.tx)
|
||||
return sanitize_tx_meta(ack.tx, coin)
|
||||
|
||||
|
||||
def request_tx_extra_data(
|
||||
@ -148,7 +148,7 @@ def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes
|
||||
tx_req.serialized = None
|
||||
gc.collect()
|
||||
if tx_hash is None:
|
||||
return sanitize_tx_output(ack.tx)
|
||||
return sanitize_tx_output(ack.tx, coin)
|
||||
else:
|
||||
return sanitize_tx_binoutput(ack.tx, coin)
|
||||
|
||||
@ -165,7 +165,7 @@ def request_tx_finish(tx_req: TxRequest):
|
||||
# ===
|
||||
|
||||
|
||||
def sanitize_sign_tx(tx: SignTx) -> SignTx:
|
||||
def sanitize_sign_tx(tx: SignTx, coin: CoinInfo) -> SignTx:
|
||||
tx.version = tx.version if tx.version is not None else 1
|
||||
tx.lock_time = tx.lock_time if tx.lock_time is not None else 0
|
||||
tx.inputs_count = tx.inputs_count if tx.inputs_count is not None else 0
|
||||
@ -177,7 +177,7 @@ def sanitize_sign_tx(tx: SignTx) -> SignTx:
|
||||
return tx
|
||||
|
||||
|
||||
def sanitize_tx_meta(tx: TransactionType) -> TransactionType:
|
||||
def sanitize_tx_meta(tx: TransactionType, coin: CoinInfo) -> TransactionType:
|
||||
tx.version = tx.version if tx.version is not None else 1
|
||||
tx.lock_time = tx.lock_time if tx.lock_time is not None else 0
|
||||
tx.inputs_cnt = tx.inputs_cnt if tx.inputs_cnt is not None else 0
|
||||
@ -216,7 +216,7 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType:
|
||||
return txi
|
||||
|
||||
|
||||
def sanitize_tx_output(tx: TransactionType) -> TxOutputType:
|
||||
def sanitize_tx_output(tx: TransactionType, coin: CoinInfo) -> TxOutputType:
|
||||
txo = tx.outputs[0]
|
||||
if txo.multisig and txo.script_type not in MULTISIG_OUTPUT_SCRIPT_TYPES:
|
||||
raise SigningError(
|
||||
|
@ -55,9 +55,7 @@ class SigningError(ValueError):
|
||||
# - check inputs, previous transactions, and outputs
|
||||
# - ask for confirmations
|
||||
# - check fee
|
||||
async def check_tx_fee(tx: SignTx, keychain: seed.Keychain):
|
||||
coin = coins.by_name(tx.coin_name)
|
||||
|
||||
async def check_tx_fee(tx: SignTx, keychain: seed.Keychain, coin: coininfo.CoinInfo):
|
||||
# h_first is used to make sure the inputs and outputs streamed in Phase 1
|
||||
# are the same as in Phase 2. it is thus not required to fully hash the
|
||||
# tx, as the SignTx info is streamed only once
|
||||
@ -225,7 +223,9 @@ async def check_tx_fee(tx: SignTx, keychain: seed.Keychain):
|
||||
|
||||
|
||||
async def sign_tx(tx: SignTx, keychain: seed.Keychain):
|
||||
tx = helpers.sanitize_sign_tx(tx)
|
||||
coin_name = tx.coin_name if tx.coin_name is not None else "Bitcoin"
|
||||
coin = coins.by_name(coin_name)
|
||||
tx = helpers.sanitize_sign_tx(tx, coin)
|
||||
|
||||
progress.init(tx.inputs_count, tx.outputs_count)
|
||||
|
||||
@ -238,14 +238,13 @@ async def sign_tx(tx: SignTx, keychain: seed.Keychain):
|
||||
authorized_in,
|
||||
wallet_path,
|
||||
multisig_fp,
|
||||
) = await check_tx_fee(tx, keychain)
|
||||
) = await check_tx_fee(tx, keychain, coin)
|
||||
|
||||
# Phase 2
|
||||
# - sign inputs
|
||||
# - check that nothing changed
|
||||
|
||||
any_segwit = True in segwit.values()
|
||||
coin = coins.by_name(tx.coin_name)
|
||||
tx_ser = TxRequestSerializedType()
|
||||
|
||||
txo_bin = TxOutputBinType()
|
||||
@ -595,7 +594,7 @@ async def get_prevtx_output_value(
|
||||
total_out = 0 # sum of output amounts
|
||||
|
||||
# STAGE_REQUEST_2_PREV_META
|
||||
tx = await helpers.request_tx_meta(tx_req, prev_hash)
|
||||
tx = await helpers.request_tx_meta(tx_req, coin, prev_hash)
|
||||
|
||||
if tx.outputs_cnt <= prev_index:
|
||||
raise SigningError(
|
||||
|
Loading…
Reference in New Issue
Block a user