1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-26 16:38:12 +00:00

refactor(core): refactor send_request_chunk()

[no changelog]
This commit is contained in:
Ondřej Vejpustek 2025-03-17 16:20:37 +01:00
parent efd4961f5e
commit 804bb2f549
2 changed files with 11 additions and 14 deletions

View File

@ -13,12 +13,7 @@ from .keychain import with_keychain_from_chain_id
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Iterable from typing import Iterable
from trezor.messages import ( from trezor.messages import EthereumNetworkInfo, EthereumSignTx, EthereumTokenInfo
EthereumNetworkInfo,
EthereumSignTx,
EthereumTokenInfo,
EthereumTxAck,
)
from apps.common.keychain import Keychain from apps.common.keychain import Keychain
@ -97,9 +92,9 @@ async def sign_tx(
progress_obj.report(60) progress_obj.report(60)
while data_left > 0: while data_left > 0:
resp = await send_request_chunk(data_left) data = await send_request_chunk(data_left)
data_left -= len(resp.data_chunk) data_left -= len(data)
sha.extend(resp.data_chunk) sha.extend(data)
# eip 155 replay protection # eip 155 replay protection
rlp.write(sha, msg.chain_id) rlp.write(sha, msg.chain_id)
@ -246,14 +241,16 @@ def _get_total_length(msg: EthereumSignTx, data_total: int) -> int:
return length 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.messages import EthereumTxAck
from trezor.wire.context import call from trezor.wire.context import call
# TODO: layoutProgress ? # TODO: layoutProgress ?
req = EthereumTxRequest() req = EthereumTxRequest()
req.data_length = min(data_left, 1024) 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( def _sign_digest(

View File

@ -103,9 +103,9 @@ async def sign_tx_eip1559(
sha.extend(data) sha.extend(data)
while data_left > 0: while data_left > 0:
resp = await send_request_chunk(data_left) data_chunk = await send_request_chunk(data_left)
data_left -= len(resp.data_chunk) data_left -= len(data_chunk)
sha.extend(resp.data_chunk) sha.extend(data_chunk)
# write_access_list # write_access_list
payload_length = sum(access_list_item_length(i) for i in msg.access_list) payload_length = sum(access_list_item_length(i) for i in msg.access_list)