pass network to NetworkDialog and Blockchain
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user