From 804bb2f5493e92627e4bed22fd12bc2df6c097bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Mon, 17 Mar 2025 16:20:37 +0100 Subject: [PATCH] refactor(core): refactor send_request_chunk() [no changelog] --- core/src/apps/ethereum/sign_tx.py | 19 ++++++++----------- core/src/apps/ethereum/sign_tx_eip1559.py | 6 +++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index 0a8b41d2ee..5ab6a65a6b 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -13,12 +13,7 @@ from .keychain import with_keychain_from_chain_id if TYPE_CHECKING: from typing import Iterable - from trezor.messages import ( - EthereumNetworkInfo, - EthereumSignTx, - EthereumTokenInfo, - EthereumTxAck, - ) + from trezor.messages import EthereumNetworkInfo, EthereumSignTx, EthereumTokenInfo from apps.common.keychain import Keychain @@ -97,9 +92,9 @@ async def sign_tx( progress_obj.report(60) while data_left > 0: - resp = await send_request_chunk(data_left) - data_left -= len(resp.data_chunk) - sha.extend(resp.data_chunk) + data = await send_request_chunk(data_left) + data_left -= len(data) + sha.extend(data) # eip 155 replay protection rlp.write(sha, msg.chain_id) @@ -246,14 +241,16 @@ def _get_total_length(msg: EthereumSignTx, data_total: int) -> int: return length -async def send_request_chunk(data_left: int) -> EthereumTxAck: +async def send_request_chunk(data_left: int) -> bytes: from trezor.messages import EthereumTxAck from trezor.wire.context import call # TODO: layoutProgress ? req = EthereumTxRequest() req.data_length = min(data_left, 1024) - return await call(req, EthereumTxAck) + resp = await call(req, EthereumTxAck) + assert resp.data_chunk is not None + return resp.data_chunk def _sign_digest( diff --git a/core/src/apps/ethereum/sign_tx_eip1559.py b/core/src/apps/ethereum/sign_tx_eip1559.py index b8857af56d..0f73374898 100644 --- a/core/src/apps/ethereum/sign_tx_eip1559.py +++ b/core/src/apps/ethereum/sign_tx_eip1559.py @@ -103,9 +103,9 @@ async def sign_tx_eip1559( sha.extend(data) while data_left > 0: - resp = await send_request_chunk(data_left) - data_left -= len(resp.data_chunk) - sha.extend(resp.data_chunk) + data_chunk = await send_request_chunk(data_left) + data_left -= len(data_chunk) + sha.extend(data_chunk) # write_access_list payload_length = sum(access_list_item_length(i) for i in msg.access_list)