From 23cde4ed727af8c52c4d119fc020e3a737e197e1 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Wed, 28 May 2025 13:01:36 +0300 Subject: [PATCH] Revert "feat(core): send address & public key response before showing `StatusScreen`" This reverts commit 946fc89449b4d082f0a795a8f251a4f8e109f74d. --- core/.changelog.d/3666.fixed | 1 - core/embed/rust/librust_qstr.h | 1 + .../rust/src/ui/api/firmware_micropython.rs | 3 ++ .../rust/src/ui/layout_bolt/ui_firmware.rs | 1 + .../rust/src/ui/layout_caesar/ui_firmware.rs | 1 + .../layout_delizia/component/status_screen.rs | 4 +-- .../src/ui/layout_delizia/flow/get_address.rs | 16 +++++++++-- .../rust/src/ui/layout_delizia/ui_firmware.rs | 23 +++++---------- core/embed/rust/src/ui/ui_firmware.rs | 1 + core/mocks/generated/trezorui_api.pyi | 1 + core/src/apps/bitcoin/get_address.py | 16 ++--------- core/src/apps/bitcoin/get_public_key.py | 28 ++++++------------- core/src/apps/bitcoin/keychain.py | 5 ++-- core/src/apps/cardano/get_address.py | 14 ++-------- core/src/apps/cardano/get_public_key.py | 10 +------ core/src/apps/cardano/seed.py | 7 ++--- core/src/apps/common/keychain.py | 9 ++---- core/src/apps/eos/get_public_key.py | 16 ++--------- core/src/apps/ethereum/get_address.py | 14 ++-------- core/src/apps/ethereum/get_public_key.py | 25 +++++------------ core/src/apps/ethereum/keychain.py | 9 +++--- .../apps/management/reset_device/__init__.py | 8 +----- core/src/apps/monero/get_address.py | 17 ++--------- core/src/apps/nem/get_address.py | 16 ++--------- core/src/apps/ripple/get_address.py | 16 ++--------- core/src/apps/solana/get_address.py | 14 ++-------- core/src/apps/solana/get_public_key.py | 14 ++-------- core/src/apps/stellar/get_address.py | 16 ++--------- core/src/apps/tezos/get_address.py | 16 ++--------- core/src/apps/tezos/get_public_key.py | 16 ++--------- core/src/trezor/ui/layouts/bolt/__init__.py | 4 --- core/src/trezor/ui/layouts/caesar/__init__.py | 4 --- .../src/trezor/ui/layouts/delizia/__init__.py | 24 +++++++--------- core/src/trezor/wire/__init__.py | 24 +--------------- core/src/trezor/wire/message_handler.py | 6 ++-- 35 files changed, 107 insertions(+), 293 deletions(-) delete mode 100644 core/.changelog.d/3666.fixed diff --git a/core/.changelog.d/3666.fixed b/core/.changelog.d/3666.fixed deleted file mode 100644 index ae3f743ed1..0000000000 --- a/core/.changelog.d/3666.fixed +++ /dev/null @@ -1 +0,0 @@ -[T3T1] Show confirmation layout after sending response to host. diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 6e371ffc73..b227ed24c2 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -757,6 +757,7 @@ static void _librust_qstrs(void) { MP_QSTR_time_ms; MP_QSTR_timer; MP_QSTR_title; + MP_QSTR_title_success; MP_QSTR_total_fee_new; MP_QSTR_total_len; MP_QSTR_touch_event; diff --git a/core/embed/rust/src/ui/api/firmware_micropython.rs b/core/embed/rust/src/ui/api/firmware_micropython.rs index 97ddf23404..761e3f9540 100644 --- a/core/embed/rust/src/ui/api/firmware_micropython.rs +++ b/core/embed/rust/src/ui/api/firmware_micropython.rs @@ -553,6 +553,7 @@ extern "C" fn new_flow_get_address(n_args: usize, args: *const Obj, kwargs: *mut let account: Option = kwargs.get(Qstr::MP_QSTR_account)?.try_into_option()?; let path: Option = kwargs.get(Qstr::MP_QSTR_path)?.try_into_option()?; let xpubs: Obj = kwargs.get(Qstr::MP_QSTR_xpubs)?; + let title_success: TString = kwargs.get(Qstr::MP_QSTR_title_success)?.try_into()?; let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?; let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?; @@ -567,6 +568,7 @@ extern "C" fn new_flow_get_address(n_args: usize, args: *const Obj, kwargs: *mut account, path, xpubs, + title_success, br_code, br_name, )?; @@ -1505,6 +1507,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// account: str | None, /// path: str | None, /// xpubs: list[tuple[str, str]], + /// title_success: str, /// br_code: ButtonRequestType, /// br_name: str, /// ) -> LayoutObj[UiResult]: diff --git a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs index 31089545e6..fc4241ce5b 100644 --- a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs @@ -599,6 +599,7 @@ impl FirmwareUI for UIBolt { _account: Option>, _path: Option>, _xpubs: Obj, + _title_success: TString<'static>, _br_code: u16, _br_name: TString<'static>, ) -> Result { diff --git a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs index 738436e259..c5800363eb 100644 --- a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs @@ -735,6 +735,7 @@ impl FirmwareUI for UICaesar { _account: Option>, _path: Option>, _xpubs: Obj, + _title_success: TString<'static>, _br_code: u16, _br_name: TString<'static>, ) -> Result { diff --git a/core/embed/rust/src/ui/layout_delizia/component/status_screen.rs b/core/embed/rust/src/ui/layout_delizia/component/status_screen.rs index 131763ea0a..9016a74a0a 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/status_screen.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/status_screen.rs @@ -172,12 +172,12 @@ impl StatusScreen { ) } - pub fn new_success_timeout(msg: TString<'static>, time_ms: u32) -> Self { + pub fn new_success_timeout(msg: TString<'static>) -> Self { Self::new( theme::ICON_SIMPLE_CHECKMARK30, theme::GREEN_LIME, theme::GREEN_LIGHT, - DismissType::Timeout(Timeout::new(time_ms)), + DismissType::Timeout(Timeout::new(TIMEOUT_MS)), msg, ) } diff --git a/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs b/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs index 65fc8f779a..6a5a7a1825 100644 --- a/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs +++ b/core/embed/rust/src/ui/layout_delizia/flow/get_address.rs @@ -20,7 +20,7 @@ use crate::{ }; use super::super::{ - component::{AddressDetails, Frame, PromptScreen, SwipeContent, VerticalMenu}, + component::{AddressDetails, Frame, PromptScreen, StatusScreen, SwipeContent, VerticalMenu}, theme, }; @@ -30,6 +30,7 @@ const QR_BORDER: i16 = 4; pub enum GetAddress { Address, Tap, + Confirmed, Menu, QrCode, AccountInfo, @@ -56,8 +57,9 @@ impl FlowController for GetAddress { fn handle_event(&'static self, msg: FlowMsg) -> Decision { match (self, msg) { (Self::Address, FlowMsg::Info) => Self::Menu.goto(), - (Self::Tap, FlowMsg::Confirmed) => self.return_msg(FlowMsg::Confirmed), + (Self::Tap, FlowMsg::Confirmed) => Self::Confirmed.swipe_up(), (Self::Tap, FlowMsg::Info) => Self::Menu.swipe_left(), + (Self::Confirmed, _) => self.return_msg(FlowMsg::Confirmed), (Self::Menu, FlowMsg::Choice(0)) => Self::QrCode.swipe_left(), (Self::Menu, FlowMsg::Choice(1)) => Self::AccountInfo.swipe_left(), (Self::Menu, FlowMsg::Choice(2)) => Self::Cancel.swipe_left(), @@ -84,6 +86,7 @@ pub fn new_get_address( account: Option>, path: Option>, xpubs: Obj, // TODO: get rid of Obj + title_success: TString<'static>, br_code: u16, br_name: TString<'static>, ) -> Result { @@ -119,6 +122,14 @@ pub fn new_get_address( .with_swipe(Direction::Down, SwipeSettings::default()) .map(super::util::map_to_confirm); + let content_confirmed = Frame::left_aligned( + TR::words__title_success.into(), + StatusScreen::new_success_timeout(title_success), + ) + .with_footer(TR::instructions__continue_in_app.into(), None) + .with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT) + .map(|_| Some(FlowMsg::Confirmed)); + // Menu let content_menu = Frame::left_aligned( "".into(), @@ -176,6 +187,7 @@ pub fn new_get_address( let mut res = SwipeFlow::new(&GetAddress::Address)?; res.add_page(&GetAddress::Address, content_address)? .add_page(&GetAddress::Tap, content_tap)? + .add_page(&GetAddress::Confirmed, content_confirmed)? .add_page(&GetAddress::Menu, content_menu)? .add_page(&GetAddress::QrCode, content_qr)? .add_page(&GetAddress::AccountInfo, content_account)? diff --git a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs index 3fecd225e7..545126e2e7 100644 --- a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs @@ -9,7 +9,6 @@ use crate::{ ui::{ component::{ connect::Connect, - swipe_detect::SwipeSettings, text::{ op::OpTextLayout, paragraphs::{ @@ -20,7 +19,7 @@ use crate::{ }, Border, CachedJpeg, ComponentExt, Empty, FormattedText, Never, Timeout, }, - geometry::{self, Direction, Offset}, + geometry::{self, Offset}, layout::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, util::{PropsList, RecoveryType}, @@ -629,6 +628,7 @@ impl FirmwareUI for UIDelizia { account: Option>, path: Option>, xpubs: Obj, + title_success: TString<'static>, br_code: u16, br_name: TString<'static>, ) -> Result { @@ -643,6 +643,7 @@ impl FirmwareUI for UIDelizia { account, path, xpubs, + title_success, br_code, br_name, )?; @@ -1087,34 +1088,24 @@ impl FirmwareUI for UIDelizia { fn show_success( title: TString<'static>, - button: TString<'static>, + _button: TString<'static>, description: TString<'static>, _allow_cancel: bool, - time_ms: u32, + _time_ms: u32, ) -> Result, Error> { - let instruction = if button.is_empty() { - TR::instructions__tap_to_continue.into() - } else { - button - }; // description used in the Footer let description = if description.is_empty() { None } else { Some(description) }; - let content = if time_ms > 0 { - StatusScreen::new_success_timeout(title, time_ms) - } else { - StatusScreen::new_success(title) - }; + let content = StatusScreen::new_success(title); let layout = LayoutObj::new(SwipeUpScreen::new( Frame::left_aligned( TR::words__title_success.into(), SwipeContent::new(content).with_no_attach_anim(), ) - .with_footer(instruction, description) - .with_swipe(Direction::Up, SwipeSettings::default()) + .with_swipeup_footer(description) .with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT), ))?; Ok(layout) diff --git a/core/embed/rust/src/ui/ui_firmware.rs b/core/embed/rust/src/ui/ui_firmware.rs index 29c2b98d56..a70efeabab 100644 --- a/core/embed/rust/src/ui/ui_firmware.rs +++ b/core/embed/rust/src/ui/ui_firmware.rs @@ -205,6 +205,7 @@ pub trait FirmwareUI { account: Option>, path: Option>, xpubs: Obj, // TODO: replace Obj + title_success: TString<'static>, br_code: u16, br_name: TString<'static>, ) -> Result; diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index 7e2406ad94..bb6501b4a3 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -367,6 +367,7 @@ def flow_get_address( account: str | None, path: str | None, xpubs: list[tuple[str, str]], + title_success: str, br_code: ButtonRequestType, br_name: str, ) -> LayoutObj[UiResult]: diff --git a/core/src/apps/bitcoin/get_address.py b/core/src/apps/bitcoin/get_address.py index d45ab13456..e3a053cf80 100644 --- a/core/src/apps/bitcoin/get_address.py +++ b/core/src/apps/bitcoin/get_address.py @@ -9,7 +9,6 @@ from .keychain import with_keychain if TYPE_CHECKING: from trezor.messages import Address, GetAddress, HDNodeType - from trezor.wire import MaybeEarlyResponse from apps.common.coininfo import CoinInfo from apps.common.keychain import Keychain @@ -36,19 +35,14 @@ def _get_xpubs( @with_keychain -async def get_address( - msg: GetAddress, keychain: Keychain, coin: CoinInfo -) -> MaybeEarlyResponse[Address]: - from trezor import TR +async def get_address(msg: GetAddress, keychain: Keychain, coin: CoinInfo) -> Address: from trezor.enums import InputScriptType from trezor.messages import Address from trezor.ui.layouts import ( confirm_multisig_different_paths_warning, confirm_multisig_warning, show_address, - show_continue_in_app, ) - from trezor.wire import early_response from apps.common.address_mac import get_address_mac from apps.common.paths import address_n_to_str, validate_path @@ -109,8 +103,6 @@ async def get_address( ): mac = get_address_mac(address, coin.slip44, keychain) - response = Address(address=address, mac=mac) - if msg.show_display: path = address_n_to_str(address_n) if multisig: @@ -164,8 +156,4 @@ async def get_address( chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - else: - return response + return Address(address=address, mac=mac) diff --git a/core/src/apps/bitcoin/get_public_key.py b/core/src/apps/bitcoin/get_public_key.py index a8d1b812ff..272aac54db 100644 --- a/core/src/apps/bitcoin/get_public_key.py +++ b/core/src/apps/bitcoin/get_public_key.py @@ -5,7 +5,6 @@ if TYPE_CHECKING: from trezor.enums import InputScriptType from trezor.messages import GetPublicKey, PublicKey from trezor.protobuf import MessageType - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @@ -14,11 +13,10 @@ async def get_public_key( msg: GetPublicKey, auth_msg: MessageType | None = None, keychain: Keychain | None = None, -) -> MaybeEarlyResponse[PublicKey]: +) -> PublicKey: from trezor import TR, wire from trezor.enums import InputScriptType from trezor.messages import HDNodeType, PublicKey, UnlockPath - from trezor.wire import early_response from apps.common import coininfo, paths from apps.common.keychain import FORBIDDEN_KEY_PATH, get_keychain @@ -88,19 +86,9 @@ async def get_public_key( descriptor = _xpub_descriptor( node, xpub_magic, address_n, script_type, keychain.root_fingerprint() ) - response = PublicKey( - node=node_type, - xpub=node_xpub, - root_fingerprint=keychain.root_fingerprint(), - descriptor=descriptor, - ) if msg.show_display: - from trezor.ui.layouts import ( - confirm_path_warning, - show_continue_in_app, - show_pubkey, - ) + from trezor.ui.layouts import confirm_path_warning, show_pubkey from apps.common.paths import address_n_to_str @@ -128,11 +116,13 @@ async def get_public_key( mismatch_title=TR.addr_mismatch__xpub_mismatch, br_name="show_xpub", ) - return await early_response( - response, show_continue_in_app(TR.address__public_key_confirmed) - ) - else: - return response + + return PublicKey( + node=node_type, + xpub=node_xpub, + root_fingerprint=keychain.root_fingerprint(), + descriptor=descriptor, + ) def _xpub_descriptor( diff --git a/core/src/apps/bitcoin/keychain.py b/core/src/apps/bitcoin/keychain.py index a3b142b2b0..d233e31473 100644 --- a/core/src/apps/bitcoin/keychain.py +++ b/core/src/apps/bitcoin/keychain.py @@ -21,7 +21,6 @@ if TYPE_CHECKING: VerifyMessage, ) from trezor.protobuf import MessageType - from trezor.wire import MaybeEarlyResponse from typing_extensions import Protocol from apps.common import coininfo @@ -44,7 +43,7 @@ if TYPE_CHECKING: script_type: InputScriptType MsgIn = TypeVar("MsgIn", bound=BitcoinMessage) - HandlerWithCoinInfo = Callable[..., Awaitable[MaybeEarlyResponse[MsgOut]]] + HandlerWithCoinInfo = Callable[..., Awaitable[MsgOut]] # BIP-45 for multisig: https://github.com/bitcoin/bips/blob/master/bip-0045.mediawiki PATTERN_BIP45 = "m/45'/[0-100]/change/address_index" @@ -317,7 +316,7 @@ def with_keychain(func: HandlerWithCoinInfo[MsgOut]) -> Handler[MsgIn, MsgOut]: async def wrapper( msg: BitcoinMessage, auth_msg: MessageType | None = None, - ) -> MaybeEarlyResponse[MsgOut]: + ) -> MsgOut: coin = _get_coin_by_name(msg.coin_name) unlock_schemas = _get_unlock_schemas(msg, auth_msg, coin) keychain = await _get_keychain_for_coin(coin, unlock_schemas) diff --git a/core/src/apps/cardano/get_address.py b/core/src/apps/cardano/get_address.py index 596b4d1ed7..e1685aff0d 100644 --- a/core/src/apps/cardano/get_address.py +++ b/core/src/apps/cardano/get_address.py @@ -4,17 +4,14 @@ from . import seed if TYPE_CHECKING: from trezor.messages import CardanoAddress, CardanoGetAddress - from trezor.wire import MaybeEarlyResponse @seed.with_keychain async def get_address( msg: CardanoGetAddress, keychain: seed.Keychain -) -> MaybeEarlyResponse[CardanoAddress]: +) -> CardanoAddress: from trezor import log, wire from trezor.messages import CardanoAddress - from trezor.ui.layouts import show_continue_in_app - from trezor.wire import early_response from . import addresses from .helpers.credential import Credential, should_show_credentials @@ -35,11 +32,7 @@ async def get_address( log.exception(__name__, e) raise wire.ProcessError("Deriving address failed") - response = CardanoAddress(address=address) - if msg.show_display: - from trezor import TR - # _display_address if should_show_credentials(address_parameters): await show_credentials( @@ -49,8 +42,5 @@ async def get_address( await show_cardano_address( address_parameters, address, msg.protocol_magic, chunkify=bool(msg.chunkify) ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return CardanoAddress(address=address) diff --git a/core/src/apps/cardano/get_public_key.py b/core/src/apps/cardano/get_public_key.py index 4b06f6af70..8b2856e87a 100644 --- a/core/src/apps/cardano/get_public_key.py +++ b/core/src/apps/cardano/get_public_key.py @@ -7,13 +7,12 @@ from . import seed if TYPE_CHECKING: from trezor.messages import CardanoGetPublicKey, CardanoPublicKey - from trezor.wire import MaybeEarlyResponse @seed.with_keychain async def get_public_key( msg: CardanoGetPublicKey, keychain: seed.Keychain -) -> MaybeEarlyResponse[CardanoPublicKey]: +) -> CardanoPublicKey: from trezor import log, wire from trezor.ui.layouts import show_pubkey @@ -38,17 +37,10 @@ async def get_public_key( raise wire.ProcessError("Deriving public key failed") if msg.show_display: - from trezor.ui.layouts import show_continue_in_app - from trezor.wire import early_response - from apps.common.paths import address_n_to_str path = address_n_to_str(address_n) await show_pubkey(key.xpub, TR.address__public_key, path=path) - return await early_response( - key, show_continue_in_app(TR.address__public_key_confirmed) - ) - return key diff --git a/core/src/apps/cardano/seed.py b/core/src/apps/cardano/seed.py index 4918abf62a..35f6b3f60c 100644 --- a/core/src/apps/cardano/seed.py +++ b/core/src/apps/cardano/seed.py @@ -21,7 +21,6 @@ if TYPE_CHECKING: from trezor import messages from trezor.crypto import bip32 from trezor.enums import CardanoDerivationType - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Handler, MsgOut from apps.common.paths import Bip32Path @@ -34,9 +33,7 @@ if TYPE_CHECKING: ) MsgIn = TypeVar("MsgIn", bound=CardanoMessages) - HandlerWithKeychain = Callable[ - [MsgIn, "Keychain"], Awaitable[MaybeEarlyResponse[MsgOut]] - ] + HandlerWithKeychain = Callable[[MsgIn, "Keychain"], Awaitable[MsgOut]] class Keychain: @@ -186,7 +183,7 @@ async def _get_keychain(derivation_type: CardanoDerivationType) -> Keychain: def with_keychain(func: HandlerWithKeychain[MsgIn, MsgOut]) -> Handler[MsgIn, MsgOut]: - async def wrapper(msg: MsgIn) -> MaybeEarlyResponse[MsgOut]: + async def wrapper(msg: MsgIn) -> MsgOut: keychain = await _get_keychain(msg.derivation_type) return await func(msg, keychain) diff --git a/core/src/apps/common/keychain.py b/core/src/apps/common/keychain.py index dda8ae09bc..16913d1529 100644 --- a/core/src/apps/common/keychain.py +++ b/core/src/apps/common/keychain.py @@ -9,7 +9,6 @@ if TYPE_CHECKING: from typing import Any, Awaitable, Callable, Iterable, TypeVar from trezor.protobuf import MessageType - from trezor.wire import MaybeEarlyResponse from typing_extensions import Protocol from .seed import Slip21Node @@ -28,10 +27,8 @@ if TYPE_CHECKING: MsgIn = TypeVar("MsgIn", bound=MessageType) MsgOut = TypeVar("MsgOut", bound=MessageType) - Handler = Callable[[MsgIn], Awaitable[MaybeEarlyResponse[MsgOut]]] - HandlerWithKeychain = Callable[ - [MsgIn, "Keychain"], Awaitable[MaybeEarlyResponse[MsgOut]] - ] + Handler = Callable[[MsgIn], Awaitable[MsgOut]] + HandlerWithKeychain = Callable[[MsgIn, "Keychain"], Awaitable[MsgOut]] class Deletable(Protocol): def __del__(self) -> None: ... @@ -197,7 +194,7 @@ def with_slip44_keychain( schemas = [s.copy() for s in schemas] def decorator(func: HandlerWithKeychain[MsgIn, MsgOut]) -> Handler[MsgIn, MsgOut]: - async def wrapper(msg: MsgIn) -> MaybeEarlyResponse[MsgOut]: + async def wrapper(msg: MsgIn) -> MsgOut: keychain = await get_keychain(curve, schemas) with keychain: return await func(msg, keychain) diff --git a/core/src/apps/eos/get_public_key.py b/core/src/apps/eos/get_public_key.py index e7b5b1c6cc..19678f0551 100644 --- a/core/src/apps/eos/get_public_key.py +++ b/core/src/apps/eos/get_public_key.py @@ -4,19 +4,14 @@ from apps.common.keychain import auto_keychain if TYPE_CHECKING: from trezor.messages import EosGetPublicKey, EosPublicKey - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @auto_keychain(__name__) -async def get_public_key( - msg: EosGetPublicKey, keychain: Keychain -) -> MaybeEarlyResponse[EosPublicKey]: +async def get_public_key(msg: EosGetPublicKey, keychain: Keychain) -> EosPublicKey: from trezor.crypto.curve import secp256k1 from trezor.messages import EosPublicKey - from trezor.ui.layouts import show_continue_in_app - from trezor.wire import early_response from apps.common import paths @@ -29,18 +24,11 @@ async def get_public_key( public_key = secp256k1.publickey(node.private_key(), True) wif = public_key_to_wif(public_key) - response = EosPublicKey(wif_public_key=wif, raw_public_key=public_key) if msg.show_display: - from trezor import TR - from . import PATTERN, SLIP44_ID path = paths.address_n_to_str(msg.address_n) account = paths.get_account_name("EOS", msg.address_n, PATTERN, SLIP44_ID) await require_get_public_key(wif, path, account) - return await early_response( - response, show_continue_in_app(TR.address__public_key_confirmed) - ) - - return response + return EosPublicKey(wif_public_key=wif, raw_public_key=public_key) diff --git a/core/src/apps/ethereum/get_address.py b/core/src/apps/ethereum/get_address.py index c38e55700a..92ab88bd08 100644 --- a/core/src/apps/ethereum/get_address.py +++ b/core/src/apps/ethereum/get_address.py @@ -4,7 +4,6 @@ from .keychain import PATTERNS_ADDRESS, with_keychain_from_path if TYPE_CHECKING: from trezor.messages import EthereumAddress, EthereumGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @@ -16,10 +15,9 @@ async def get_address( msg: EthereumGetAddress, keychain: Keychain, defs: Definitions, -) -> MaybeEarlyResponse[EthereumAddress]: +) -> EthereumAddress: from trezor.messages import EthereumAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths @@ -32,11 +30,8 @@ async def get_address( node = keychain.derive(address_n) address = address_from_bytes(node.ethereum_pubkeyhash(), defs.network) - response = EthereumAddress(address=address) if msg.show_display: - from trezor import TR - slip44_id = address_n[1] # it depends on the network (ETH vs ETC...) await show_address( address, @@ -46,8 +41,5 @@ async def get_address( ), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return EthereumAddress(address=address) diff --git a/core/src/apps/ethereum/get_public_key.py b/core/src/apps/ethereum/get_public_key.py index 8767677c60..c39061d3ed 100644 --- a/core/src/apps/ethereum/get_public_key.py +++ b/core/src/apps/ethereum/get_public_key.py @@ -2,32 +2,21 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from trezor.messages import EthereumGetPublicKey, EthereumPublicKey - from trezor.wire import MaybeEarlyResponse -async def get_public_key( - msg: EthereumGetPublicKey, -) -> MaybeEarlyResponse[EthereumPublicKey]: +async def get_public_key(msg: EthereumGetPublicKey) -> EthereumPublicKey: from ubinascii import hexlify - from trezor.messages import EthereumPublicKey, GetPublicKey, PublicKey - from trezor.ui.layouts import show_continue_in_app, show_pubkey - from trezor.wire import early_response + from trezor.messages import EthereumPublicKey, GetPublicKey + from trezor.ui.layouts import show_pubkey from apps.bitcoin import get_public_key as bitcoin_get_public_key # we use the Bitcoin format for Ethereum xpubs - btc_pubkey_msg = GetPublicKey(address_n=msg.address_n, show_display=False) - btc_resp = await bitcoin_get_public_key.get_public_key(btc_pubkey_msg) - assert PublicKey.is_type_of(btc_resp) + btc_pubkey_msg = GetPublicKey(address_n=msg.address_n) + resp = await bitcoin_get_public_key.get_public_key(btc_pubkey_msg) - response = EthereumPublicKey(node=btc_resp.node, xpub=btc_resp.xpub) if msg.show_display: - from trezor import TR + await show_pubkey(hexlify(resp.node.public_key).decode()) - await show_pubkey(hexlify(response.node.public_key).decode()) - return await early_response( - response, show_continue_in_app(TR.address__public_key_confirmed) - ) - - return response + return EthereumPublicKey(node=resp.node, xpub=resp.xpub) diff --git a/core/src/apps/ethereum/keychain.py b/core/src/apps/ethereum/keychain.py index 6da77364f0..a4300da31a 100644 --- a/core/src/apps/ethereum/keychain.py +++ b/core/src/apps/ethereum/keychain.py @@ -17,7 +17,6 @@ if TYPE_CHECKING: EthereumSignTxEIP1559, EthereumSignTypedData, ) - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Handler, Keychain, MsgOut @@ -31,7 +30,7 @@ if TYPE_CHECKING: HandlerAddressN = Callable[ [MsgInAddressN, Keychain, definitions.Definitions], - Awaitable[MaybeEarlyResponse[MsgOut]], + Awaitable[MsgOut], ] # messages for "with_keychain_and_defs_from_chain_id" decorator @@ -43,7 +42,7 @@ if TYPE_CHECKING: HandlerChainId = Callable[ [MsgInSignTx, Keychain, definitions.Definitions], - Awaitable[MaybeEarlyResponse[MsgOut]], + Awaitable[MsgOut], ] @@ -121,7 +120,7 @@ def with_keychain_from_path( def decorator( func: HandlerAddressN[MsgInAddressN, MsgOut] ) -> Handler[MsgInAddressN, MsgOut]: - async def wrapper(msg: MsgInAddressN) -> MaybeEarlyResponse[MsgOut]: + async def wrapper(msg: MsgInAddressN) -> MsgOut: slip44 = _slip44_from_address_n(msg.address_n) defs = _defs_from_message(msg, slip44=slip44) schemas = _schemas_from_network(patterns, defs.network) @@ -138,7 +137,7 @@ def with_keychain_from_chain_id( func: HandlerChainId[MsgInSignTx, MsgOut] ) -> Handler[MsgInSignTx, MsgOut]: # this is only for SignTx, and only PATTERN_ADDRESS is allowed - async def wrapper(msg: MsgInSignTx) -> MaybeEarlyResponse[MsgOut]: + async def wrapper(msg: MsgInSignTx) -> MsgOut: defs = _defs_from_message(msg, chain_id=msg.chain_id) schemas = _schemas_from_network(PATTERNS_ADDRESS, defs.network) keychain = await get_keychain(CURVE, schemas) diff --git a/core/src/apps/management/reset_device/__init__.py b/core/src/apps/management/reset_device/__init__.py index 4311d18838..4634f47a5a 100644 --- a/core/src/apps/management/reset_device/__init__.py +++ b/core/src/apps/management/reset_device/__init__.py @@ -144,12 +144,7 @@ async def reset_device(msg: ResetDevice) -> Success: async def _entropy_check(secret: bytes) -> bool: """Returns True to indicate that entropy check loop should end.""" - from trezor.messages import ( - EntropyCheckContinue, - EntropyCheckReady, - GetPublicKey, - PublicKey, - ) + from trezor.messages import EntropyCheckContinue, EntropyCheckReady, GetPublicKey from trezor.wire.context import call_any from apps.bitcoin.get_public_key import get_public_key @@ -176,7 +171,6 @@ async def _entropy_check(secret: bytes) -> bool: curve_name = req.ecdsa_curve_name or coininfo.by_name(req.coin_name).curve_name keychain = Keychain(seed, curve_name, [paths.AlwaysMatchingSchema]) msg = await get_public_key(req, keychain=keychain) - assert PublicKey.is_type_of(msg) async def _backup_bip39(mnemonic: str) -> None: diff --git a/core/src/apps/monero/get_address.py b/core/src/apps/monero/get_address.py index 7c0f4b76a5..3653f0af11 100644 --- a/core/src/apps/monero/get_address.py +++ b/core/src/apps/monero/get_address.py @@ -4,19 +4,15 @@ from apps.common.keychain import auto_keychain if TYPE_CHECKING: from trezor.messages import MoneroAddress, MoneroGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @auto_keychain(__name__) -async def get_address( - msg: MoneroGetAddress, keychain: Keychain -) -> MaybeEarlyResponse[MoneroAddress]: +async def get_address(msg: MoneroGetAddress, keychain: Keychain) -> MoneroAddress: from trezor import wire from trezor.messages import MoneroAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths from apps.monero import misc @@ -69,11 +65,7 @@ async def get_address( crypto_helpers.encodepoint(pub_view), ) - response = MoneroAddress(address=addr.encode()) - if msg.show_display: - from trezor import TR - from . import PATTERN, SLIP44_ID await show_address( @@ -83,8 +75,5 @@ async def get_address( account=paths.get_account_name("XMR", msg.address_n, PATTERN, SLIP44_ID), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return MoneroAddress(address=addr.encode()) diff --git a/core/src/apps/nem/get_address.py b/core/src/apps/nem/get_address.py index 0a2269b6e7..c09299ae73 100644 --- a/core/src/apps/nem/get_address.py +++ b/core/src/apps/nem/get_address.py @@ -6,18 +6,14 @@ from . import CURVE, PATTERNS, SLIP44_ID if TYPE_CHECKING: from trezor.messages import NEMAddress, NEMGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @with_slip44_keychain(*PATTERNS, slip44_id=SLIP44_ID, curve=CURVE) -async def get_address( - msg: NEMGetAddress, keychain: Keychain -) -> MaybeEarlyResponse[NEMAddress]: +async def get_address(msg: NEMGetAddress, keychain: Keychain) -> NEMAddress: from trezor.messages import NEMAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths @@ -32,11 +28,8 @@ async def get_address( node = keychain.derive(address_n) address = node.nem_address(network) - response = NEMAddress(address=address) if msg.show_display: - from trezor import TR - from . import PATTERNS, SLIP44_ID await show_address( @@ -47,8 +40,5 @@ async def get_address( network=get_network_str(network), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return NEMAddress(address=address) diff --git a/core/src/apps/ripple/get_address.py b/core/src/apps/ripple/get_address.py index 052f74111a..1450669817 100644 --- a/core/src/apps/ripple/get_address.py +++ b/core/src/apps/ripple/get_address.py @@ -4,19 +4,15 @@ from apps.common.keychain import auto_keychain if TYPE_CHECKING: from trezor.messages import RippleAddress, RippleGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @auto_keychain(__name__) -async def get_address( - msg: RippleGetAddress, keychain: Keychain -) -> MaybeEarlyResponse[RippleAddress]: +async def get_address(msg: RippleGetAddress, keychain: Keychain) -> RippleAddress: # NOTE: local imports here saves 20 bytes from trezor.messages import RippleAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths @@ -29,11 +25,8 @@ async def get_address( node = keychain.derive(address_n) pubkey = node.public_key() address = address_from_public_key(pubkey) - response = RippleAddress(address=address) if msg.show_display: - from trezor import TR - from . import PATTERN, SLIP44_ID await show_address( @@ -42,8 +35,5 @@ async def get_address( account=paths.get_account_name("XRP", msg.address_n, PATTERN, SLIP44_ID), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return RippleAddress(address=address) diff --git a/core/src/apps/solana/get_address.py b/core/src/apps/solana/get_address.py index 858f2084a7..b543b8245d 100644 --- a/core/src/apps/solana/get_address.py +++ b/core/src/apps/solana/get_address.py @@ -8,7 +8,6 @@ from . import CURVE, PATTERNS, SLIP44_ID if TYPE_CHECKING: from trezor.messages import SolanaAddress, SolanaGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @@ -17,10 +16,9 @@ if TYPE_CHECKING: async def get_address( msg: SolanaGetAddress, keychain: Keychain, -) -> MaybeEarlyResponse[SolanaAddress]: +) -> SolanaAddress: from trezor.messages import SolanaAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths @@ -28,18 +26,12 @@ async def get_address( public_key = derive_public_key(keychain, msg.address_n) address = base58.encode(public_key) - response = SolanaAddress(address=address) if msg.show_display: - from trezor import TR - await show_address( address, path=paths.address_n_to_str(msg.address_n), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return SolanaAddress(address=address) diff --git a/core/src/apps/solana/get_public_key.py b/core/src/apps/solana/get_public_key.py index cbf53f9e46..787ff1beff 100644 --- a/core/src/apps/solana/get_public_key.py +++ b/core/src/apps/solana/get_public_key.py @@ -9,7 +9,6 @@ from . import CURVE, PATTERNS, SLIP44_ID if TYPE_CHECKING: from trezor.messages import SolanaGetPublicKey, SolanaPublicKey - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @@ -17,26 +16,19 @@ if TYPE_CHECKING: @with_slip44_keychain(*PATTERNS, slip44_id=SLIP44_ID, curve=CURVE) async def get_public_key( msg: SolanaGetPublicKey, keychain: Keychain -) -> MaybeEarlyResponse[SolanaPublicKey]: +) -> SolanaPublicKey: from trezor.messages import SolanaPublicKey - from trezor.ui.layouts import show_continue_in_app, show_pubkey - from trezor.wire import early_response + from trezor.ui.layouts import show_pubkey public_key = derive_public_key(keychain, msg.address_n) - response = SolanaPublicKey(public_key=public_key) if msg.show_display: - from trezor import TR - from apps.common.paths import address_n_to_str path = address_n_to_str(msg.address_n) await show_pubkey(base58.encode(public_key), path=path) - return await early_response( - response, show_continue_in_app(TR.address__public_key_confirmed) - ) - return response + return SolanaPublicKey(public_key=public_key) def derive_public_key(keychain: Keychain, address_n: list[int]) -> bytes: diff --git a/core/src/apps/stellar/get_address.py b/core/src/apps/stellar/get_address.py index d67d5ee949..65b323bbf8 100644 --- a/core/src/apps/stellar/get_address.py +++ b/core/src/apps/stellar/get_address.py @@ -4,18 +4,14 @@ from apps.common.keychain import auto_keychain if TYPE_CHECKING: from trezor.messages import StellarAddress, StellarGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @auto_keychain(__name__) -async def get_address( - msg: StellarGetAddress, keychain: Keychain -) -> MaybeEarlyResponse[StellarAddress]: +async def get_address(msg: StellarGetAddress, keychain: Keychain) -> StellarAddress: from trezor.messages import StellarAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths, seed @@ -28,11 +24,8 @@ async def get_address( node = keychain.derive(address_n) pubkey = seed.remove_ed25519_prefix(node.public_key()) address = helpers.address_from_public_key(pubkey) - response = StellarAddress(address=address) if msg.show_display: - from trezor import TR - from . import PATTERN, SLIP44_ID await show_address( @@ -42,8 +35,5 @@ async def get_address( account=paths.get_account_name("XLM", msg.address_n, PATTERN, SLIP44_ID), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return StellarAddress(address=address) diff --git a/core/src/apps/tezos/get_address.py b/core/src/apps/tezos/get_address.py index d173526859..8269fce154 100644 --- a/core/src/apps/tezos/get_address.py +++ b/core/src/apps/tezos/get_address.py @@ -6,19 +6,15 @@ from . import CURVE, PATTERNS, SLIP44_ID if TYPE_CHECKING: from trezor.messages import TezosAddress, TezosGetAddress - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @with_slip44_keychain(*PATTERNS, slip44_id=SLIP44_ID, curve=CURVE) -async def get_address( - msg: TezosGetAddress, keychain: Keychain -) -> MaybeEarlyResponse[TezosAddress]: +async def get_address(msg: TezosGetAddress, keychain: Keychain) -> TezosAddress: from trezor.crypto import hashlib from trezor.messages import TezosAddress - from trezor.ui.layouts import show_address, show_continue_in_app - from trezor.wire import early_response + from trezor.ui.layouts import show_address from apps.common import paths, seed @@ -33,11 +29,8 @@ async def get_address( pk = seed.remove_ed25519_prefix(node.public_key()) pkh = hashlib.blake2b(pk, outlen=helpers.PUBLIC_KEY_HASH_SIZE).digest() address = helpers.base58_encode_check(pkh, helpers.TEZOS_ED25519_ADDRESS_PREFIX) - response = TezosAddress(address=address) if msg.show_display: - from trezor import TR - from . import PATTERNS, SLIP44_ID await show_address( @@ -46,8 +39,5 @@ async def get_address( account=paths.get_account_name("XTZ", address_n, PATTERNS, SLIP44_ID), chunkify=bool(msg.chunkify), ) - return await early_response( - response, show_continue_in_app(TR.address__confirmed) - ) - return response + return TezosAddress(address=address) diff --git a/core/src/apps/tezos/get_public_key.py b/core/src/apps/tezos/get_public_key.py index 253c5db326..aab680d71e 100644 --- a/core/src/apps/tezos/get_public_key.py +++ b/core/src/apps/tezos/get_public_key.py @@ -6,18 +6,14 @@ from . import CURVE, PATTERNS, SLIP44_ID if TYPE_CHECKING: from trezor.messages import TezosGetPublicKey, TezosPublicKey - from trezor.wire import MaybeEarlyResponse from apps.common.keychain import Keychain @with_slip44_keychain(*PATTERNS, slip44_id=SLIP44_ID, curve=CURVE) -async def get_public_key( - msg: TezosGetPublicKey, keychain: Keychain -) -> MaybeEarlyResponse[TezosPublicKey]: +async def get_public_key(msg: TezosGetPublicKey, keychain: Keychain) -> TezosPublicKey: from trezor.messages import TezosPublicKey - from trezor.ui.layouts import show_continue_in_app, show_pubkey - from trezor.wire import early_response + from trezor.ui.layouts import show_pubkey from apps.common import paths, seed @@ -28,18 +24,12 @@ async def get_public_key( node = keychain.derive(msg.address_n) pk = seed.remove_ed25519_prefix(node.public_key()) pk_prefixed = helpers.base58_encode_check(pk, helpers.TEZOS_PUBLICKEY_PREFIX) - response = TezosPublicKey(public_key=pk_prefixed) if msg.show_display: - from trezor import TR - from . import PATTERNS, SLIP44_ID account = paths.get_account_name("XTZ", msg.address_n, PATTERNS, SLIP44_ID) path = paths.address_n_to_str(msg.address_n) await show_pubkey(pk_prefixed, account=account, path=path) - return await early_response( - response, show_continue_in_app(TR.address__public_key_confirmed) - ) - return response + return TezosPublicKey(public_key=pk_prefixed) diff --git a/core/src/trezor/ui/layouts/bolt/__init__.py b/core/src/trezor/ui/layouts/bolt/__init__.py index bfec308108..0ecd355e20 100644 --- a/core/src/trezor/ui/layouts/bolt/__init__.py +++ b/core/src/trezor/ui/layouts/bolt/__init__.py @@ -443,10 +443,6 @@ def show_success( ) -async def show_continue_in_app(content: str) -> None: - return - - async def confirm_output( address: str, amount: str, diff --git a/core/src/trezor/ui/layouts/caesar/__init__.py b/core/src/trezor/ui/layouts/caesar/__init__.py index 2e37189721..b35d9db0c1 100644 --- a/core/src/trezor/ui/layouts/caesar/__init__.py +++ b/core/src/trezor/ui/layouts/caesar/__init__.py @@ -507,10 +507,6 @@ def show_success( ) -async def show_continue_in_app(content: str) -> None: - return - - async def confirm_output( address: str, amount: str, diff --git a/core/src/trezor/ui/layouts/delizia/__init__.py b/core/src/trezor/ui/layouts/delizia/__init__.py index 9fee55b436..c1f388458b 100644 --- a/core/src/trezor/ui/layouts/delizia/__init__.py +++ b/core/src/trezor/ui/layouts/delizia/__init__.py @@ -279,6 +279,12 @@ async def show_address( ) return result + title_success = ( + TR.address__public_key_confirmed + if title in ("XPUB", TR.address__public_key) + else TR.address__confirmed + ) + await raise_if_not_confirmed( trezorui_api.flow_get_address( address=address, @@ -291,6 +297,7 @@ async def show_address( account=account, path=path, xpubs=[(xpub_title(i), xpub) for i, xpub in enumerate(xpubs)], + title_success=title_success, br_name=br_name, br_code=br_code, ), @@ -386,33 +393,22 @@ def show_danger( def show_success( - br_name: str | None, + br_name: str, content: str, subheader: str | None = None, button: str | None = None, - time_ms: int = 0, ) -> Awaitable[None]: return raise_if_not_confirmed( trezorui_api.show_success( title=content, - button=button or "", - description=subheader or "", - time_ms=time_ms, + button="", + description=subheader if subheader else "", ), br_name, ButtonRequestType.Success, ) -def show_continue_in_app(content: str) -> Awaitable[None]: - return show_success( - content=content, - button=TR.instructions__continue_in_app, - time_ms=3200, - br_name=None, - ) - - async def confirm_output( address: str, amount: str | None = None, diff --git a/core/src/trezor/wire/__init__.py b/core/src/trezor/wire/__init__.py index f031305e6a..b831710e58 100644 --- a/core/src/trezor/wire/__init__.py +++ b/core/src/trezor/wire/__init__.py @@ -41,7 +41,7 @@ if __debug__: if TYPE_CHECKING: from trezorio import WireInterface - from typing import Any, Awaitable, Callable, Coroutine, Generic, TypeAlias, TypeVar + from typing import Any, Callable, Coroutine, TypeVar Msg = TypeVar("Msg", bound=protobuf.MessageType) HandlerTask = Coroutine[Any, Any, protobuf.MessageType] @@ -49,28 +49,6 @@ if TYPE_CHECKING: LoadedMessageType = TypeVar("LoadedMessageType", bound=protobuf.MessageType) - class EarlyResponse(Generic[Msg]): - """Marker type (when the response is sent before the last layout is shown).""" - - MaybeEarlyResponse: TypeAlias = Msg | EarlyResponse[Msg] - -else: - EarlyResponse = object - - -_EARLY_RESPONSE = EarlyResponse() - - -async def early_response(response: Msg, layout: Awaitable[None]) -> EarlyResponse[Msg]: - from .context import get_context - - # first, send the response back to the client - await get_context().write(response) - # then, show the success layout - await layout - # return a special marker object - return _EARLY_RESPONSE - class BufferProvider: def __init__(self, size: int) -> None: diff --git a/core/src/trezor/wire/message_handler.py b/core/src/trezor/wire/message_handler.py index d2cb718c0a..5393927016 100644 --- a/core/src/trezor/wire/message_handler.py +++ b/core/src/trezor/wire/message_handler.py @@ -60,8 +60,6 @@ async def handle_single_message(ctx: Context, msg: Message) -> bool: the type of message is supposed to be optimized and not disrupt the running state, this function will return `True`. """ - from . import _EARLY_RESPONSE - if __debug__: try: msg_type = protobuf.type_for_wire(msg.type).MESSAGE_NAME @@ -74,6 +72,8 @@ async def handle_single_message(ctx: Context, msg: Message) -> bool: iface=ctx.iface, ) + res_msg: protobuf.MessageType | None = None + # We need to find a handler for this message type. try: handler: Handler = find_handler(ctx.iface, msg.type) @@ -156,7 +156,7 @@ async def handle_single_message(ctx: Context, msg: Message) -> bool: log.exception(__name__, exc, iface=ctx.iface) res_msg = failure(exc) - if res_msg is not _EARLY_RESPONSE: + if res_msg is not None: # perform the write outside the big try-except block, so that usb write # problem bubbles up await ctx.write(res_msg)