From 91d477c3c4a5ec331ce4410b11c941f94fe93cad Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Wed, 20 Nov 2024 10:34:07 +0100 Subject: [PATCH] fixup! refactor(core): abstract cache and context [no changelog] --- core/src/trezor/wire/codec/codec_context.py | 17 +---------------- core/src/trezor/wire/message_handler.py | 2 +- core/src/trezor/wire/protocol_common.py | 3 --- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/core/src/trezor/wire/codec/codec_context.py b/core/src/trezor/wire/codec/codec_context.py index 7eb610a69e..c664124187 100644 --- a/core/src/trezor/wire/codec/codec_context.py +++ b/core/src/trezor/wire/codec/codec_context.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Awaitable, Container, overload +from typing import TYPE_CHECKING, Awaitable, Container from storage import cache_codec from storage.cache_common import DataCache, InvalidSessionError @@ -27,7 +27,6 @@ class CodecContext(Context): iface: WireInterface, buffer: bytearray, ) -> None: - self.iface = iface self.buffer = buffer super().__init__(iface) @@ -35,20 +34,6 @@ class CodecContext(Context): """Read a whole message from the wire without parsing it.""" return codec_v1.read_message(self.iface, self.buffer) - if TYPE_CHECKING: - - @overload - async def read( - self, expected_types: Container[int] - ) -> protobuf.MessageType: ... - - @overload - async def read( - self, expected_types: Container[int], expected_type: type[LoadedMessageType] - ) -> LoadedMessageType: ... - - reading: bool = False - async def read( self, expected_types: Container[int], diff --git a/core/src/trezor/wire/message_handler.py b/core/src/trezor/wire/message_handler.py index bdaa1207e8..2593d4ddc7 100644 --- a/core/src/trezor/wire/message_handler.py +++ b/core/src/trezor/wire/message_handler.py @@ -26,7 +26,7 @@ def wrap_protobuf_load( expected_type: type[LoadedMessageType], ) -> LoadedMessageType: try: - if __debug__: + if __debug__ and utils.EMULATOR: log.debug( __name__, "Buffer to be parsed to a LoadedMessage: %s", diff --git a/core/src/trezor/wire/protocol_common.py b/core/src/trezor/wire/protocol_common.py index 8185427361..cf01e91cdd 100644 --- a/core/src/trezor/wire/protocol_common.py +++ b/core/src/trezor/wire/protocol_common.py @@ -22,9 +22,6 @@ class Message: self.data = message_data self.type = message_type - def to_bytes(self) -> bytes: - return self.type.to_bytes(2, "big") + self.data - class Context: channel_id: bytes