tpass network to NetworkDialog and Blockchain - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 73901a001a77ae33391eb560f63a2e091f9a2d36 DIR parent 2df129cfbf5cd034948918a76bce7019cde23db4 HTML Author: thomasv <thomasv@gitorious> Date: Tue, 10 Sep 2013 18:27:32 +0200 pass network to NetworkDialog and Blockchain Diffstat: M gui/gui_classic.py | 4 ++-- M gui/installwizard.py | 4 +--- M gui/network_dialog.py | 8 +++++--- M lib/blockchain.py | 15 +++++++++++---- M lib/network.py | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) --- DIR diff --git a/gui/gui_classic.py b/gui/gui_classic.py t@@ -1366,7 +1366,7 @@ class ElectrumWindow(QMainWindow): console.history = self.config.get("console-history",[]) console.history_index = len(console.history) - console.updateNamespace({'wallet' : self.wallet, 'network' : self.wallet.network, 'gui':self}) + console.updateNamespace({'wallet' : self.wallet, 'network' : self.network, 'gui':self}) console.updateNamespace({'util' : util, 'bitcoin':bitcoin}) c = commands.Commands(self.wallet, self.wallet.interface, lambda: self.console.set_json(True)) t@@ -2230,7 +2230,7 @@ class ElectrumWindow(QMainWindow): self.receive_tab_set_mode(expert_cb.isChecked()) def run_network_dialog(self): - NetworkDialog(self.wallet.interface, self.config, self).do_exec() + NetworkDialog(self.wallet.network, self.config, self).do_exec() def closeEvent(self, event): g = self.geometry() DIR diff --git a/gui/installwizard.py b/gui/installwizard.py t@@ -18,8 +18,6 @@ class InstallWizard(QDialog): QDialog.__init__(self) self.config = config self.network = network - self.interface = network.interface - self.blockchain = network.blockchain self.storage = storage t@@ -217,7 +215,7 @@ class InstallWizard(QDialog): return if b2.isChecked(): - return NetworkDialog(self.interface, self.config, None).do_exec() + return NetworkDialog(self.network, self.config, None).do_exec() elif b1.isChecked(): self.config.set_key('auto_cycle', True, True) DIR diff --git a/gui/network_dialog.py b/gui/network_dialog.py t@@ -31,20 +31,21 @@ protocol_names = ['TCP', 'HTTP', 'SSL', 'HTTPS'] protocol_letters = 'thsg' class NetworkDialog(QDialog): - def __init__(self, interface, config, parent): + def __init__(self, network, config, parent): QDialog.__init__(self,parent) self.setModal(1) self.setWindowTitle(_('Server')) self.setMinimumSize(375, 20) - self.interface = interface + self.network = network + self.interface = interface = network.interface self.config = config self.protocol = None if parent: if interface.is_connected: - status = _("Connected to")+" %s"%(interface.host) + "\n%d "%(parent.wallet.verifier.blockchain.height)+_("blocks") + status = _("Connected to")+" %s"%(interface.host) + "\n%d "%(network.blockchain.height)+_("blocks") else: status = _("Not connected") server = interface.server t@@ -55,6 +56,7 @@ class NetworkDialog(QDialog): self.servers = interface.get_servers() + vbox = QVBoxLayout() vbox.setSpacing(30) DIR diff --git a/lib/blockchain.py b/lib/blockchain.py t@@ -24,10 +24,11 @@ from bitcoin import * class Blockchain(threading.Thread): - def __init__(self, config): + def __init__(self, config, network): threading.Thread.__init__(self) self.daemon = True self.config = config + self.network = network self.lock = threading.Lock() self.height = 0 self.local_height = 0 t@@ -35,6 +36,7 @@ class Blockchain(threading.Thread): self.headers_url = 'http://headers.electrum.org/blockchain_headers' self.set_local_height() self.queue = Queue.Queue() + self.servers_height = {} def stop(self): t@@ -63,12 +65,13 @@ class Blockchain(threading.Thread): if not result: continue i, result = result - header= result.get('result') + header = result.get('result') height = header.get('block_height') + self.servers_height[i.server] = height if height > self.local_height + 50: self.get_chunks(i, header, height) - i.network.trigger_callback('updated') + self.network.trigger_callback('updated') if height > self.local_height: # get missing parts from interface (until it connects to my chain) t@@ -87,8 +90,12 @@ class Blockchain(threading.Thread): print_error("error", i.server) # todo: dismiss that server - i.network.trigger_callback('updated') + self.network.trigger_callback('updated') + h = self.servers_height.get(self.network.interface.server) + if h is not None and h < height: + print "server is lagging", height - i.network.interface.height + self.network.interface.stop() DIR diff --git a/lib/network.py b/lib/network.py t@@ -12,7 +12,7 @@ class Network(threading.Thread): self.daemon = True self.config = config self.lock = threading.Lock() - self.blockchain = Blockchain(config) + self.blockchain = Blockchain(config, self) self.interfaces = {} self.queue = Queue.Queue() self.default_server = self.config.get('server')