tadd blockchain.get_name method, update kivy gui - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit b424a83a5732d7b284e8ecf5ba0b748c5e3619d6 DIR parent 9576f8510d77222c1431e0e699487c5bfa6915aa HTML Author: ThomasV <thomasv@electrum.org> Date: Wed, 19 Jul 2017 09:29:20 +0200 add blockchain.get_name method, update kivy gui Diffstat: M gui/kivy/main_window.py | 23 ++++++----------------- M gui/kivy/uix/ui_screens/network.kv | 7 +++---- M gui/qt/network_dialog.py | 9 ++++----- M lib/blockchain.py | 11 ++++++++--- M lib/network.py | 9 +-------- 5 files changed, 22 insertions(+), 37 deletions(-) --- DIR diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py t@@ -81,6 +81,7 @@ class ElectrumWindow(App): server_host = StringProperty('') server_port = StringProperty('') blockchain_name = StringProperty('') + blockchain_checkpoint = NumericProperty(0) auto_connect = BooleanProperty(False) def on_auto_connect(self, instance, x): t@@ -103,12 +104,13 @@ class ElectrumWindow(App): def choose_blockchain_dialog(self, dt): from uix.dialogs.choice_dialog import ChoiceDialog + chains = self.network.get_blockchains() def cb(name): for index, b in self.network.blockchains.items(): if name == self.network.get_blockchain_name(b): self.network.follow_chain(index) #self.block - names = [self.network.get_blockchain_name(b) for b in self.network.blockchains.values()] + names = [self.network.blockchains[b].get_name() for b in chains] if len(names) >1: ChoiceDialog(_('Choose your chain'), names, '', cb).open() t@@ -590,23 +592,10 @@ class ElectrumWindow(App): self.network.register_callback(self.on_network, interests) self.tabs = self.root.ids['tabs'] - def blockchain_status(self): - if len(self.network.blockchains)>1: - msg = self.network.get_blockchain_name(self.network.blockchain()) - else: - msg = _('Genesis') - return msg - - def blockchain_info(self): - if len(self.network.blockchains)>1: - checkpoint = self.network.get_checkpoint() - msg = _('Fork detected at block %d')%checkpoint - else: - msg = _('The blockchain appears to be one') - return msg - def on_network(self, event, *args): - self.blockchain_name = self.blockchain_status() + chain = self.network.blockchain() + self.blockchain_checkpoint = chain.get_checkpoint() + self.blockchain_name = chain.get_name() if self.network.interface: self.server_host = self.network.interface.host if event == 'updated': DIR diff --git a/gui/kivy/uix/ui_screens/network.kv b/gui/kivy/uix/ui_screens/network.kv t@@ -46,9 +46,8 @@ Popup: CardSeparator SettingsItem: - title: app.blockchain_info() + title: _('Fork detected at block %d')%app.blockchain_checkpoint if app.blockchain_checkpoint else _('No fork detected') fork_description: (_('You are following branch') if app.auto_connect else _("Your server is on branch")) + ' ' + app.blockchain_name - description: _('Everything is fine') if self.disabled else self.fork_description + description: self.fork_description if app.blockchain_checkpoint else '' action: app.choose_blockchain_dialog - disabled: len(app.network.blockchains) == 1 - + disabled: app.blockchain_checkpoint == 0 DIR diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py t@@ -95,14 +95,13 @@ class NodesListWidget(QTreeWidget): def update(self, network): self.clear() self.addChild = self.addTopLevelItem - checkpoint = network.get_checkpoint() chains = network.get_blockchains() n_chains = len(chains) for k, items in chains.items(): b = network.blockchains[k] - name = network.get_blockchain_name(b) + name = b.get_name() if n_chains >1: - x = QTreeWidgetItem([name + '@%d'%checkpoint, '%d'%b.height()]) + x = QTreeWidgetItem([name + '@%d'%b.get_checkpoint(), '%d'%b.height()]) x.setData(0, Qt.UserRole, 1) x.setData(1, Qt.UserRole, b.checkpoint) else: t@@ -361,8 +360,8 @@ class NetworkChoiceLayout(object): chains = self.network.get_blockchains() if len(chains)>1: chain = self.network.blockchain() - checkpoint = self.network.get_checkpoint() - name = self.network.get_blockchain_name(self.network.blockchain()) + checkpoint = chain.get_checkpoint() + name = chain.get_name() msg = _('Chain split detected at block %d')%checkpoint + '\n' msg += (_('You are following branch') if auto_connect else _('Your server is on branch'))+ ' ' + name msg += ' (%d %s)' % (chain.get_branch_size(), _('blocks')) DIR diff --git a/lib/blockchain.py b/lib/blockchain.py t@@ -110,10 +110,15 @@ class Blockchain(util.PrintError): children = filter(lambda y: y.parent==self, blockchains.values()) return max([x.checkpoint for x in children]) if children else None - def get_branch_size(self): + def get_checkpoint(self): mc = self.get_max_child() - checkpoint = mc if mc is not None else self.checkpoint - return self.height() - checkpoint + 1 + return mc if mc is not None else self.checkpoint + + def get_branch_size(self): + return self.height() - self.get_checkpoint() + 1 + + def get_name(self): + return self.get_hash(self.get_checkpoint()).lstrip('00')[0:10] def check_header(self, header): header_hash = hash_header(header) DIR diff --git a/lib/network.py b/lib/network.py t@@ -696,9 +696,6 @@ class Network(util.DaemonThread): if b.catch_up == server: b.catch_up = None - def get_checkpoint(self): - return max(self.blockchains.keys()) - def new_interface(self, server, socket): # todo: get tip first, then decide which checkpoint to use. self.add_recent_server(server) t@@ -823,6 +820,7 @@ class Network(util.DaemonThread): interface.bad_header = header delta = interface.tip - height next_height = max(0, interface.tip - 2 * delta) + elif interface.mode == 'binary': if chain: interface.good = height t@@ -1011,11 +1009,6 @@ class Network(util.DaemonThread): out[k] = r return out - def get_blockchain_name(self, blockchain): - checkpoint = self.get_checkpoint() - _hash = blockchain.get_hash(checkpoint) - return _hash.lstrip('00')[0:10] - def follow_chain(self, index): blockchain = self.blockchains.get(index) if blockchain: