logging: basics
This commit is contained in:
@@ -3,9 +3,10 @@ from struct import pack
|
||||
|
||||
from electrum import ecc
|
||||
from electrum.i18n import _
|
||||
from electrum.util import PrintError, UserCancelled, UserFacingException
|
||||
from electrum.util import UserCancelled, UserFacingException
|
||||
from electrum.keystore import bip39_normalize_passphrase
|
||||
from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 as parse_path
|
||||
from electrum.logging import Logger
|
||||
|
||||
from trezorlib.client import TrezorClient
|
||||
from trezorlib.exceptions import TrezorFailure, Cancelled, OutdatedFirmwareError
|
||||
@@ -26,12 +27,13 @@ MESSAGES = {
|
||||
}
|
||||
|
||||
|
||||
class TrezorClientBase(PrintError):
|
||||
class TrezorClientBase(Logger):
|
||||
def __init__(self, transport, handler, plugin):
|
||||
self.client = TrezorClient(transport, ui=self)
|
||||
self.plugin = plugin
|
||||
self.device = plugin.device
|
||||
self.handler = handler
|
||||
Logger.__init__(self)
|
||||
|
||||
self.msg = None
|
||||
self.creating_wallet = False
|
||||
@@ -111,7 +113,7 @@ class TrezorClientBase(PrintError):
|
||||
def timeout(self, cutoff):
|
||||
'''Time out the client if the last operation was before cutoff.'''
|
||||
if self.last_operation < cutoff:
|
||||
self.print_error("timed out")
|
||||
self.logger.info("timed out")
|
||||
self.clear_session()
|
||||
|
||||
def i4b(self, x):
|
||||
@@ -158,17 +160,17 @@ class TrezorClientBase(PrintError):
|
||||
def clear_session(self):
|
||||
'''Clear the session to force pin (and passphrase if enabled)
|
||||
re-entry. Does not leak exceptions.'''
|
||||
self.print_error("clear session:", self)
|
||||
self.logger.info(f"clear session: {self}")
|
||||
self.prevent_timeouts()
|
||||
try:
|
||||
self.client.clear_session()
|
||||
except BaseException as e:
|
||||
# If the device was removed it has the same effect...
|
||||
self.print_error("clear_session: ignoring error", str(e))
|
||||
self.logger.info(f"clear_session: ignoring error {e}")
|
||||
|
||||
def close(self):
|
||||
'''Called when Our wallet was closed or the device removed.'''
|
||||
self.print_error("closing client")
|
||||
self.logger.info("closing client")
|
||||
self.clear_session()
|
||||
|
||||
def is_uptodate(self):
|
||||
|
||||
@@ -11,11 +11,15 @@ from electrum.plugin import Device
|
||||
from electrum.transaction import deserialize, Transaction
|
||||
from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey
|
||||
from electrum.base_wizard import ScriptTypeNotSupported, HWD_SETUP_NEW_WALLET
|
||||
from electrum.logging import get_logger
|
||||
|
||||
from ..hw_wallet import HW_PluginBase
|
||||
from ..hw_wallet.plugin import (is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data,
|
||||
LibraryFoundButUnusable)
|
||||
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
|
||||
try:
|
||||
import trezorlib
|
||||
import trezorlib.transport
|
||||
@@ -32,8 +36,7 @@ try:
|
||||
|
||||
TREZORLIB = True
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
_logger.exception('error importing trezorlib')
|
||||
TREZORLIB = False
|
||||
|
||||
RECOVERY_TYPE_SCRAMBLED_WORDS, RECOVERY_TYPE_MATRIX = range(2)
|
||||
@@ -145,17 +148,17 @@ class TrezorPlugin(HW_PluginBase):
|
||||
|
||||
def create_client(self, device, handler):
|
||||
try:
|
||||
self.print_error("connecting to device at", device.path)
|
||||
self.logger.info(f"connecting to device at {device.path}")
|
||||
transport = trezorlib.transport.get_transport(device.path)
|
||||
except BaseException as e:
|
||||
self.print_error("cannot connect at", device.path, str(e))
|
||||
self.logger.info(f"cannot connect at {device.path} {e}")
|
||||
return None
|
||||
|
||||
if not transport:
|
||||
self.print_error("cannot connect at", device.path)
|
||||
self.logger.info(f"cannot connect at {device.path}")
|
||||
return
|
||||
|
||||
self.print_error("connected to device at", device.path)
|
||||
self.logger.info(f"connected to device at {device.path}")
|
||||
# note that this call can still raise!
|
||||
return TrezorClientBase(transport, handler, self)
|
||||
|
||||
@@ -208,7 +211,7 @@ class TrezorPlugin(HW_PluginBase):
|
||||
except UserCancelled:
|
||||
exit_code = 1
|
||||
except BaseException as e:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
self.logger.exception('')
|
||||
handler.show_error(str(e))
|
||||
exit_code = 1
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user