def queue_json_response(self, c): # uncomment to debug if self.debug: print_error( "<--",c ) msg_id = c.get('id') error = c.get('error') if error: print_error("received error:", c) if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop(msg_id) callback(self,{'method':method, 'params':params, 'error':error, 'id':msg_id}) return if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop(msg_id) result = c.get('result') else: # notification method = c.get('method') params = c.get('params') if method == 'blockchain.numblocks.subscribe': result = params[0] params = [] elif method == 'blockchain.headers.subscribe': result = params[0] params = [] elif method == 'blockchain.address.subscribe': addr = params[0] result = params[1] params = [addr] with self.lock: for k,v in self.subscriptions.items(): if (method, params) in v: callback = k break else: print_error( "received unexpected notification", method, params) print_error( self.subscriptions ) return callback(self, {'method':method, 'params':params, 'result':result, 'id':msg_id})
def queue_json_response(self, c): # uncomment to debug if self.debug: print_error("<--", c) msg_id = c.get("id") error = c.get("error") if error: print_error("received error:", c) if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop(msg_id) callback(self, {"method": method, "params": params, "error": error, "id": msg_id}) return if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop(msg_id) result = c.get("result") else: # notification method = c.get("method") params = c.get("params") if method == "blockchain.numblocks.subscribe": result = params[0] params = [] elif method == "blockchain.headers.subscribe": result = params[0] params = [] elif method == "blockchain.address.subscribe": addr = params[0] result = params[1] params = [addr] with self.lock: for k, v in self.subscriptions.items(): if (method, params) in v: callback = k break else: print_error("received unexpected notification", method, params) print_error(self.subscriptions) return callback(self, {"method": method, "params": params, "result": result, "id": msg_id})
def queue_json_response(self, c): # uncomment to debug if self.debug: print_error("<--", c) msg_id = c.get('id') error = c.get('error') if error: print_error("received error:", c) if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop( msg_id) callback( self, { 'method': method, 'params': params, 'error': error, 'id': msg_id }) return if msg_id is not None: with self.lock: method, params, callback = self.unanswered_requests.pop(msg_id) result = c.get('result') else: # notification method = c.get('method') params = c.get('params') if method == 'blockchain.numblocks.subscribe': result = params[0] params = [] elif method == 'blockchain.headers.subscribe': result = params[0] params = [] elif method == 'blockchain.address.subscribe': addr = params[0] result = params[1] params = [addr] with self.lock: for k, v in self.subscriptions.items(): if (method, params) in v: callback = k break else: print_error("received unexpected notification", method, params) print_error(self.subscriptions) return callback(self, { 'method': method, 'params': params, 'result': result, 'id': msg_id })