electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c70484455c561b53664ba349cb88587bc349efc9
parent e66a5bbfc4d55fb2d7e290df2764ddf952192554
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 16 Oct 2020 17:55:40 +0200

kivy: use our logger, not kivy's; and log more exceptions.

Diffstat:
Melectrum/gui/kivy/__init__.py | 8+++++---
Melectrum/gui/kivy/main_window.py | 23+++++++++++++----------
Melectrum/gui/kivy/uix/dialogs/installwizard.py | 2++
Melectrum/gui/kivy/uix/dialogs/lightning_channels.py | 14++++++++++----
Melectrum/gui/kivy/uix/dialogs/lightning_open_channel.py | 7+++++--
Melectrum/gui/kivy/uix/screens.py | 10+++++++---
6 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/electrum/gui/kivy/__init__.py b/electrum/gui/kivy/__init__.py @@ -39,7 +39,8 @@ except ImportError: # minimum required version for kivy kivy.require('1.8.0') -from kivy.logger import Logger + +from electrum.logging import Logger if TYPE_CHECKING: from electrum.simple_config import SimpleConfig @@ -49,10 +50,11 @@ if TYPE_CHECKING: -class ElectrumGui: +class ElectrumGui(Logger): def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'): - Logger.debug('ElectrumGUI: initialising') + Logger.__init__(self) + self.logger.debug('ElectrumGUI: initialising') self.daemon = daemon self.network = daemon.network self.config = config diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py @@ -21,11 +21,11 @@ from electrum.invoices import PR_PAID, PR_FAILED from electrum import blockchain from electrum.network import Network, TxBroadcastError, BestEffortRequestFailed from electrum.interface import PREFERRED_NETWORK_PROTOCOL, ServerAddr +from electrum.logging import Logger from .i18n import _ from kivy.app import App from kivy.core.window import Window -from kivy.logger import Logger from kivy.utils import platform from kivy.properties import (OptionProperty, AliasProperty, ObjectProperty, StringProperty, ListProperty, BooleanProperty, NumericProperty) @@ -87,7 +87,7 @@ if TYPE_CHECKING: from electrum.paymentrequest import PaymentRequest -class ElectrumWindow(App): +class ElectrumWindow(App, Logger): electrum_config = ObjectProperty(None) language = StringProperty('en') @@ -228,7 +228,7 @@ class ElectrumWindow(App): self._process_invoice_str(invoice_queued) def on_language(self, instance, language): - Logger.info('language: {}'.format(language)) + self.logger.info('language: {}'.format(language)) _.switch_lang(language) def update_history(self, *dt): @@ -236,12 +236,12 @@ class ElectrumWindow(App): self.history_screen.update() def on_quotes(self, d): - Logger.info("on_quotes") + self.logger.info("on_quotes") self._trigger_update_status() self._trigger_update_history() def on_history(self, d): - Logger.info("on_history") + self.logger.info("on_history") if self.wallet: self.wallet.clear_coin_price_cache() self._trigger_update_history() @@ -368,6 +368,7 @@ class ElectrumWindow(App): self.password = None App.__init__(self)#, **kwargs) + Logger.__init__(self) self.electrum_config = config = kwargs.get('config', None) # type: SimpleConfig self.language = config.get('language', 'en') @@ -556,6 +557,7 @@ class ElectrumWindow(App): try: return func(self, *args, **kwargs) except Exception as e: + self.logger.exception('crash on startup') from .uix.dialogs.crash_reporter import CrashReporter # show the crash reporter, and when it's closed, shutdown the app cr = CrashReporter(self, exctype=type(e), value=e, tb=e.__traceback__) @@ -568,7 +570,7 @@ class ElectrumWindow(App): ''' This is the start point of the kivy ui ''' import time - Logger.info('Time to on_start: {} <<<<<<<<'.format(time.process_time())) + self.logger.info('Time to on_start: {} <<<<<<<<'.format(time.process_time())) Window.bind(size=self.on_size, on_keyboard=self.on_keyboard) Window.bind(on_key_down=self.on_key_down) #Window.softinput_mode = 'below_target' @@ -691,7 +693,7 @@ class ElectrumWindow(App): self._on_decrypted_storage(storage) def on_stop(self): - Logger.info('on_stop') + self.logger.info('on_stop') self.stop_wallet() def stop_wallet(self): @@ -832,7 +834,7 @@ class ElectrumWindow(App): self.update_proxy_str(self.proxy_config) def on_network_event(self, event, *args): - Logger.info('network event: '+ event) + self.logger.info('network event: '+ event) if event == 'network_updated': self._trigger_update_interfaces() self._trigger_update_status() @@ -983,7 +985,7 @@ class ElectrumWindow(App): notification.notify('Electrum', message, app_icon=icon, app_name='Electrum') except ImportError: - Logger.Error('Notification: needs plyer; `sudo python3 -m pip install plyer`') + self.logger.Error('Notification: needs plyer; `sudo python3 -m pip install plyer`') def on_pause(self): self.pause_time = time.time() @@ -1246,7 +1248,7 @@ class ElectrumWindow(App): if self.wallet.has_password(): try: self.wallet.check_password(pw) - except: + except InvalidPassword: self.show_error("Invalid PIN") return self.stop_wallet() @@ -1348,6 +1350,7 @@ class ElectrumWindow(App): try: self.wallet.lnbackups.import_channel_backup(encrypted) except Exception as e: + self.logger.exception("failed to import backup") self.show_error("failed to import backup" + '\n' + str(e)) return self.lightning_channels_dialog() diff --git a/electrum/gui/kivy/uix/dialogs/installwizard.py b/electrum/gui/kivy/uix/dialogs/installwizard.py @@ -1081,6 +1081,7 @@ class InstallWizard(BaseWizard, Widget): try: task() except Exception as err: + self.logger.exception('') self.show_error(str(err)) # on completion hide message Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1) @@ -1089,6 +1090,7 @@ class InstallWizard(BaseWizard, Widget): try: on_finished() except Exception as e: + self.logger.exception('') self.show_error(str(e)) Clock.schedule_once(lambda dt: protected_on_finished(), -1) diff --git a/electrum/gui/kivy/uix/dialogs/lightning_channels.py b/electrum/gui/kivy/uix/dialogs/lightning_channels.py @@ -8,6 +8,7 @@ from kivy.uix.popup import Popup from kivy.clock import Clock from electrum.util import bh2u +from electrum.logging import Logger from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id from electrum.lnchannel import AbstractChannel, Channel from electrum.gui.kivy.i18n import _ @@ -289,10 +290,11 @@ Builder.load_string(r''' ''') -class ChannelBackupPopup(Popup): +class ChannelBackupPopup(Popup, Logger): def __init__(self, chan: AbstractChannel, app: 'ElectrumWindow', **kwargs): - super(ChannelBackupPopup,self).__init__(**kwargs) + Popup.__init__(self, **kwargs) + Logger.__init__(self) self.chan = chan self.app = app self.short_id = format_short_channel_id(chan.short_channel_id) @@ -312,6 +314,7 @@ class ChannelBackupPopup(Popup): coro.result(5) self.app.show_info(_('Channel closed')) except Exception as e: + self.logger.exception("Could not close channel") self.app.show_info(_('Could not close channel: ') + repr(e)) # repr because str(Exception()) == '' def remove_backup(self): @@ -324,10 +327,11 @@ class ChannelBackupPopup(Popup): self.app.wallet.lnbackups.remove_channel_backup(self.chan.channel_id) self.dismiss() -class ChannelDetailsPopup(Popup): +class ChannelDetailsPopup(Popup, Logger): def __init__(self, chan: Channel, app: 'ElectrumWindow', **kwargs): - super(ChannelDetailsPopup,self).__init__(**kwargs) + Popup.__init__(self, **kwargs) + Logger.__init__(self) self.is_closed = chan.is_closed() self.is_redeemed = chan.is_redeemed() self.app = app @@ -364,6 +368,7 @@ class ChannelDetailsPopup(Popup): coro.result(5) self.app.show_info(_('Channel closed')) except Exception as e: + self.logger.exception("Could not close channel") self.app.show_info(_('Could not close channel: ') + repr(e)) # repr because str(Exception()) == '' def remove_channel(self): @@ -402,6 +407,7 @@ class ChannelDetailsPopup(Popup): coro.result(1) self.app.show_info(_('Channel closed, you may need to wait at least {} blocks, because of CSV delays'.format(self.chan.config[REMOTE].to_self_delay))) except Exception as e: + self.logger.exception("Could not force close channel") self.app.show_info(_('Could not force close channel: ') + repr(e)) # repr because str(Exception()) == '' diff --git a/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py b/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py @@ -8,6 +8,7 @@ from electrum.lnaddr import lndecode from electrum.util import bh2u from electrum.bitcoin import COIN import electrum.simple_config as config +from electrum.logging import Logger from .label_dialog import LabelDialog @@ -94,7 +95,7 @@ Builder.load_string(''' disabled: not root.pubkey or not root.amount ''') -class LightningOpenChannelDialog(Factory.Popup): +class LightningOpenChannelDialog(Factory.Popup, Logger): def ipport_dialog(self): def callback(text): self.ipport = text @@ -107,7 +108,8 @@ class LightningOpenChannelDialog(Factory.Popup): self.pubkey = suggested.hex() def __init__(self, app, lnaddr=None, msg=None): - super(LightningOpenChannelDialog, self).__init__() + Factory.Popup.__init__(self) + Logger.__init__(self) self.app = app # type: ElectrumWindow self.lnaddr = lnaddr self.msg = msg @@ -159,6 +161,7 @@ class LightningOpenChannelDialog(Factory.Popup): push_amt_sat=0, password=password) except Exception as e: + self.logger.exception("Problem opening channel") self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e)) return n = chan.constraints.funding_txn_minimum_depth diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py @@ -21,7 +21,6 @@ from kivy.uix.image import Image from kivy.lang import Builder from kivy.factory import Factory from kivy.utils import platform -from kivy.logger import Logger from electrum.util import profiler, parse_URI, format_time, InvalidPassword, NotEnoughFunds, Fiat from electrum.invoices import (PR_TYPE_ONCHAIN, PR_TYPE_LN, PR_DEFAULT_EXPIRATION_WHEN_CREATING, @@ -36,6 +35,7 @@ from electrum import simple_config from electrum.simple_config import FEERATE_WARNING_HIGH_FEE, FEE_RATIO_HIGH_WARNING from electrum.lnaddr import lndecode from electrum.lnutil import RECEIVED, SENT, PaymentFailure +from electrum.logging import Logger from .dialogs.question import Question from .dialogs.lightning_open_channel import LightningOpenChannelDialog @@ -173,12 +173,16 @@ class HistoryScreen(CScreen): history_card.data = [self.get_card(item) for item in history] -class SendScreen(CScreen): +class SendScreen(CScreen, Logger): kvname = 'send' payment_request = None # type: Optional[PaymentRequest] parsed_URI = None + def __init__(self): + CScreen.__init__(self) + Logger.__init__(self) + def set_URI(self, text: str): if not self.app.wallet: return @@ -361,7 +365,7 @@ class SendScreen(CScreen): self.app.show_error(_("Not enough funds")) return except Exception as e: - Logger.exception('') + self.logger.exception('') self.app.show_error(repr(e)) return if rbf: