mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
python: use better error when no ui is supplied
This commit is contained in:
parent
00564f4a1c
commit
6fabaa7bd8
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from types import SimpleNamespace
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
@ -43,6 +44,21 @@ Or visit https://wallet.trezor.io/
|
|||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
|
|
||||||
|
def _no_ui_selected(*args, **kwargs):
|
||||||
|
raise RuntimeError(
|
||||||
|
"You did not supply a UI object. You were warned that this would crash soon. "
|
||||||
|
"That's what happened now.\n "
|
||||||
|
"You need to supply a UI object to TrezorClient constructor."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_NO_UI_OBJECT = SimpleNamespace(
|
||||||
|
button_request=_no_ui_selected,
|
||||||
|
get_passphrase=_no_ui_selected,
|
||||||
|
get_pin=_no_ui_selected,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_buttonrequest_value(code):
|
def get_buttonrequest_value(code):
|
||||||
# Converts integer code to its string representation of ButtonRequestType
|
# Converts integer code to its string representation of ButtonRequestType
|
||||||
return [
|
return [
|
||||||
@ -91,14 +107,21 @@ class TrezorClient:
|
|||||||
the user might not need to enter their passphrase again.
|
the user might not need to enter their passphrase again.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, transport, ui=None, state=None):
|
def __init__(self, transport, ui=_NO_UI_OBJECT, state=None):
|
||||||
LOG.info("creating client instance for device: {}".format(transport.get_path()))
|
LOG.info("creating client instance for device: {}".format(transport.get_path()))
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
if ui is None:
|
# XXX remove when old Electrum has been cycled out.
|
||||||
warnings.warn("UI class not supplied. This will probably crash soon.")
|
# explanation: We changed the API in 0.11 and this broke older versions
|
||||||
|
# of Electrum (incl. all its forks). We want to display an intelligent error
|
||||||
|
# message instead of crashing for no reason (see DEPRECATION_ERROR and MovedTo),
|
||||||
|
# so we are not allowed to crash in constructor.
|
||||||
|
# I'd keep this until, say, end of 2019 (or version 0.12), and then drop
|
||||||
|
# the default value for `ui` argument and all related functionality.
|
||||||
|
if ui is _NO_UI_OBJECT:
|
||||||
|
warnings.warn("UI object not supplied. This will probably crash soon.")
|
||||||
|
|
||||||
self.session_counter = 0
|
self.session_counter = 0
|
||||||
self.init_device()
|
self.init_device()
|
||||||
|
Loading…
Reference in New Issue
Block a user