electrum

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

commit af6391318927f7ff686ff70111f9c1e96c38cb2b
parent fef15f9c0289fa38d5146d28d15e82cdad38f6f0
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 18 Sep 2018 16:49:48 +0200

network triggers: rm 'updated'; more fine-grained instead

rm 'interfaces'
add 'wallet_updated', add 'network_updated'

Diffstat:
Melectrum/gui/kivy/main_window.py | 11+++++------
Melectrum/gui/qt/main_window.py | 13++++++++-----
Melectrum/gui/qt/network_dialog.py | 2+-
Melectrum/gui/stdio.py | 4++--
Melectrum/gui/text.py | 2+-
Melectrum/interface.py | 8++++----
Melectrum/network.py | 15++++++---------
Melectrum/synchronizer.py | 2+-
8 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py @@ -490,7 +490,7 @@ class ElectrumWindow(App): activity.bind(on_new_intent=self.on_new_intent) # connect callbacks if self.network: - interests = ['updated', 'status', 'new_transaction', 'verified', 'interfaces'] + interests = ['wallet_updated', 'network_updated', 'status', 'new_transaction', 'verified'] self.network.register_callback(self.on_network_event, interests) self.network.register_callback(self.on_fee, ['fee']) self.network.register_callback(self.on_fee_histogram, ['fee_histogram']) @@ -669,17 +669,16 @@ class ElectrumWindow(App): def on_network_event(self, event, *args): Logger.info('network event: '+ event) - if event == 'interfaces': + if event == 'network_updated': self._trigger_update_interfaces() - elif event == 'updated': + self._trigger_update_status() + elif event == 'wallet_updated': self._trigger_update_wallet() self._trigger_update_status() elif event == 'status': self._trigger_update_status() elif event == 'new_transaction': - wallet, tx = args - if wallet == self.wallet: - self._trigger_update_wallet() + self._trigger_update_wallet() elif event == 'verified': self._trigger_update_wallet() diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -188,7 +188,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): # network callbacks if self.network: self.network_signal.connect(self.on_network_qt) - interests = ['updated', 'new_transaction', 'status', + interests = ['wallet_updated', 'network_updated', 'new_transaction', 'status', 'banner', 'verified', 'fee', 'fee_histogram'] # To avoid leaking references to "self" that prevent the # window from being GC-ed when closed, callbacks should be @@ -295,10 +295,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.show_error(str(exc_info[1])) def on_network(self, event, *args): - if event == 'updated': - self.need_update.set() + if event == 'wallet_updated': + wallet = args[0] + if wallet == self.wallet: + self.need_update.set() + self.network_signal.emit('status', None) + elif event == 'network_updated': self.gui_object.network_updated_signal_obj.network_updated_signal \ .emit(event, args) + self.network_signal.emit('status', None) elif event == 'new_transaction': wallet, tx = args if wallet == self.wallet: @@ -766,9 +771,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.balance_label.setText(text) self.status_button.setIcon( icon ) - def update_wallet(self): - self.update_status() if self.wallet.up_to_date or not self.network or not self.network.is_connected(): self.update_tabs() diff --git a/electrum/gui/qt/network_dialog.py b/electrum/gui/qt/network_dialog.py @@ -52,7 +52,7 @@ class NetworkDialog(QDialog): vbox.addLayout(Buttons(CloseButton(self))) self.network_updated_signal_obj.network_updated_signal.connect( self.on_update) - network.register_callback(self.on_network, ['updated', 'interfaces']) + network.register_callback(self.on_network, ['network_updated']) def on_network(self, event, *args): self.network_updated_signal_obj.network_updated_signal.emit(event, args) diff --git a/electrum/gui/stdio.py b/electrum/gui/stdio.py @@ -37,7 +37,7 @@ class ElectrumGui: self.wallet.start_network(self.network) self.contacts = self.wallet.contacts - self.network.register_callback(self.on_network, ['updated', 'banner']) + self.network.register_callback(self.on_network, ['wallet_updated', 'network_updated', 'banner']) self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ @@ -50,7 +50,7 @@ class ElectrumGui: self.num_commands = len(self.commands) def on_network(self, event, *args): - if event == 'updated': + if event in ['wallet_updated', 'network_updated']: self.updated() elif event == 'banner': self.print_banner() diff --git a/electrum/gui/text.py b/electrum/gui/text.py @@ -62,7 +62,7 @@ class ElectrumGui: self.history = None if self.network: - self.network.register_callback(self.update, ['updated']) + self.network.register_callback(self.update, ['wallet_updated', 'network_updated']) self.tab_names = [_("History"), _("Send"), _("Receive"), _("Addresses"), _("Contacts"), _("Banner")] self.num_tabs = len(self.tab_names) diff --git a/electrum/interface.py b/electrum/interface.py @@ -375,7 +375,6 @@ class Interface(PrintError): header_queue = asyncio.Queue() await self.session.subscribe('blockchain.headers.subscribe', [], header_queue) while True: - self.network.notify('updated') item = await header_queue.get() raw_header = item[0] height = raw_header['height'] @@ -394,6 +393,7 @@ class Interface(PrintError): # in the simple case, height == self.tip+1 if height <= self.tip: await self.sync_until(height) + self.network.trigger_callback('network_updated') self.network.switch_lagging_interface() async def sync_until(self, height, next_height=None): @@ -406,10 +406,10 @@ class Interface(PrintError): could_connect, num_headers = await self.request_chunk(height, next_height) if not could_connect: if height <= constants.net.max_checkpoint(): - raise Exception('server chain conflicts with checkpoints or genesis') + raise GracefulDisconnect('server chain conflicts with checkpoints or genesis') last, height = await self.step(height) continue - self.network.notify('updated') + self.network.trigger_callback('network_updated') height = (height // 2016 * 2016) + num_headers assert height <= next_height+1, (height, self.tip) last = 'catchup' @@ -536,7 +536,7 @@ class Interface(PrintError): if chain or can_connect: return False if checkp: - raise Exception("server chain conflicts with checkpoints") + raise GracefulDisconnect("server chain conflicts with checkpoints") return True bad, bad_header = height, header diff --git a/electrum/network.py b/electrum/network.py @@ -367,12 +367,10 @@ class Network(PrintError): value = self.config.fee_estimates elif key == 'fee_histogram': value = self.config.mempool_fees - elif key == 'updated': - value = (self.get_local_height(), self.get_server_height()) elif key == 'servers': value = self.get_servers() - elif key == 'interfaces': - value = self.get_interfaces() + else: + raise Exception('unexpected trigger key {}'.format(key)) return value def notify(self, key): @@ -547,7 +545,7 @@ class Network(PrintError): self.switch_to_interface(server_str) else: self.switch_lagging_interface() - self.notify('updated') + self.trigger_callback('network_updated') def switch_to_random_interface(self): '''Switch to a random connected server other than the current one''' @@ -603,8 +601,7 @@ class Network(PrintError): i.group.spawn(self.request_server_info(i))) self.trigger_callback('default_server_changed') self.set_status('connected') - self.notify('updated') - self.notify('interfaces') + self.trigger_callback('network_updated') @with_interface_lock def close_interface(self, interface): @@ -633,7 +630,7 @@ class Network(PrintError): self.set_status('disconnected') if server in self.interfaces: self.close_interface(self.interfaces[server]) - self.notify('interfaces') + self.trigger_callback('network_updated') @aiosafe async def new_interface(self, server): @@ -664,7 +661,7 @@ class Network(PrintError): self.switch_to_interface(server) self.add_recent_server(server) - self.notify('interfaces') + self.trigger_callback('network_updated') def init_headers_file(self): b = blockchain.blockchains[0] diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py @@ -177,4 +177,4 @@ class Synchronizer(PrintError): up_to_date = self.is_up_to_date() if up_to_date != self.wallet.is_up_to_date(): self.wallet.set_up_to_date(up_to_date) - self.wallet.network.trigger_callback('updated') + self.wallet.network.trigger_callback('wallet_updated', self.wallet)