electrum

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

commit 73901a001a77ae33391eb560f63a2e091f9a2d36
parent 2df129cfbf5cd034948918a76bce7019cde23db4
Author: thomasv <thomasv@gitorious>
Date:   Tue, 10 Sep 2013 18:27:32 +0200

pass network to NetworkDialog and Blockchain

Diffstat:
Mgui/gui_classic.py | 4++--
Mgui/installwizard.py | 4+---
Mgui/network_dialog.py | 8+++++---
Mlib/blockchain.py | 15+++++++++++----
Mlib/network.py | 2+-
5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/gui/gui_classic.py b/gui/gui_classic.py @@ -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)) @@ -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() diff --git a/gui/installwizard.py b/gui/installwizard.py @@ -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 @@ -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) diff --git a/gui/network_dialog.py b/gui/network_dialog.py @@ -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 @@ -55,6 +56,7 @@ class NetworkDialog(QDialog): self.servers = interface.get_servers() + vbox = QVBoxLayout() vbox.setSpacing(30) diff --git a/lib/blockchain.py b/lib/blockchain.py @@ -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 @@ -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): @@ -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) @@ -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() diff --git a/lib/network.py b/lib/network.py @@ -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')