tadd missing Network methods to NetworkProxy - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 8f025db8007b88beee24ea2a030c04751ef8bc06 (DIR) parent b4bed1ccaa3aca4d29d9d54b042c17912a01ef46 (HTM) Author: ThomasV <thomasv@gitorious> Date: Mon, 10 Mar 2014 20:58:18 +0100 add missing Network methods to NetworkProxy Diffstat: M lib/daemon.py | 57 +++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 19 deletions(-) --- (DIR) diff --git a/lib/daemon.py b/lib/daemon.py t@@ -86,10 +86,10 @@ class NetworkProxy(threading.Thread): method, params, callback = self.unanswered_requests.pop(msg_id) result = response.get('result') - callback({'method':method, 'params':params, 'result':result, 'id':msg_id}) + callback(None, {'method':method, 'params':params, 'result':result, 'id':msg_id}) - def send(self, messages, callback): + def subscribe(self, messages, callback): # detect if it is a subscription with self.lock: if self.subscriptions.get(callback) is None: t@@ -121,7 +121,7 @@ class NetworkProxy(threading.Thread): def synchronous_get(self, requests, timeout=100000000): queue = Queue.Queue() - ids = self.do_send(requests, queue.put) + ids = self.do_send(requests, lambda i,x: queue.put(x)) id2 = ids[:] res = {} while ids: t@@ -137,10 +137,29 @@ class NetworkProxy(threading.Thread): def get_servers(self): - return self.synchronous_get([('network.getservers',[])])[0] + return self.synchronous_get([('network.get_servers',[])])[0] + + def get_header(self, height): + return self.synchronous_get([('network.get_header',[height])])[0] + + def get_local_height(self): + return self.synchronous_get([('network.get_local_height',[])])[0] + + def is_connected(self): + return self.synchronous_get([('network.is_connected',[])])[0] + + def is_up_to_date(self): + return self.synchronous_get([('network.is_up_to_date',[])])[0] + + def main_server(self): + return self.synchronous_get([('network.main_server',[])])[0] def stop(self): - return self.synchronous_get([('network.shutdown',[])])[0] + return self.synchronous_get([('daemon.shutdown',[])])[0] + + + def trigger_callback(self, cb): + pass t@@ -199,15 +218,20 @@ class ClientThread(threading.Thread): _id = request['id'] if method.startswith('network.'): - if method == 'network.shutdown': - self.server.running = False - r = {'id':_id, 'result':True} - elif method == 'network.getservers': - servers = self.network.get_servers() - r = {'id':_id, 'result':servers} - else: - r = {'id':_id, 'error':'unknown method'} - self.queue.put(r) + out = {'id':_id} + try: + f = getattr(self.network, method[8:]) + except AttributeError: + out['error'] = "unknown method" + try: + out['result'] = f(*params) + except BaseException as e: + out['error'] =str(e) + self.queue.put(out) + + if method == 'daemon.shutdown': + self.server.running = False + self.queue.put({'id':_id, 'result':True}) return def cb(i,r): t@@ -234,9 +258,6 @@ class ClientThread(threading.Thread): #print "-->", r -#Server: -# start network() object -# accept connections, forward requests class NetworkServer: t@@ -269,8 +290,6 @@ class NetworkServer: t = time.time() client = ClientThread(self, self.network, connection) client.start() - #print "Done." -