From 22fcb9e5215219ccdbbbdf9b36cdc20fed54fd0a Mon Sep 17 00:00:00 2001 From: Julian Tosh Date: Fri, 6 Jul 2012 13:36:13 -0700 Subject: [PATCH] Adding user enabled debug messages for server communications --- lib/interface.py | 25 +++++++++++++++++-------- lib/wallet.py | 3 +++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/interface.py b/lib/interface.py index eb3f41e50..71f9b9b57 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -49,7 +49,7 @@ def old_to_new(d): class Interface(threading.Thread): - def __init__(self, host, port): + def __init__(self, host, port, debug_server): threading.Thread.__init__(self) self.daemon = True self.host = host @@ -67,6 +67,8 @@ class Interface(threading.Thread): self.responses = Queue.Queue() self.unanswered_requests = {} + self.debug_server = debug_server + def init_socket(self): pass @@ -76,7 +78,9 @@ class Interface(threading.Thread): def queue_json_response(self, c): - #print "<--",c + if self.debug_server: + print "<--",c + msg_id = c.get('id') error = c.get('error') @@ -117,9 +121,10 @@ class Interface(threading.Thread): class PollingInterface(Interface): """ non-persistent connection. synchronous calls""" - def __init__(self, host, port): - Interface.__init__(self, host, port) + def __init__(self, host, port, debug_server): + Interface.__init__(self, host, port, debug_server) self.session_id = None + self.debug_server = debug_server def get_history(self, address): self.send([('blockchain.address.get_history', [address] )]) @@ -227,8 +232,9 @@ class HttpStratumInterface(PollingInterface): class TcpStratumInterface(Interface): """json-rpc over persistent TCP connection, asynchronous""" - def __init__(self, host, port): - Interface.__init__(self, host, port) + def __init__(self, host, port, debug_server): + Interface.__init__(self, host, port, debug_server) + self.debug_server = debug_server def init_socket(self): self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) @@ -279,7 +285,10 @@ class TcpStratumInterface(Interface): method, params = m request = json.dumps( { 'id':self.message_id, 'method':method, 'params':params } ) self.unanswered_requests[self.message_id] = method, params - #print "-->",request + + if self.debug_server: + print "-->",request + self.message_id += 1 out += request + '\n' @@ -321,7 +330,7 @@ class WalletSynchronizer(threading.Thread): print "unknown protocol" InterfaceClass = TcpStratumInterface - self.interface = InterfaceClass(host, port) + self.interface = InterfaceClass(host, port, self.wallet.debug_server) self.wallet.interface = self.interface diff --git a/lib/wallet.py b/lib/wallet.py index 3334004a8..5de094c69 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -277,6 +277,7 @@ class Wallet: self.receipts = {} # signed URIs self.receipt = None # next receipt self.addressbook = [] # outgoing addresses, for payments + self.debug_server = False # write server communication debug info to stdout # not saved self.tx_history = {} @@ -638,6 +639,7 @@ class Wallet: 'prioritized_addresses':self.prioritized_addresses, 'expert_mode':self.expert_mode, 'gap_limit':self.gap_limit, + 'debug_server':self.debug_server, } f = open(self.path,"w") f.write( repr(s) ) @@ -681,6 +683,7 @@ class Wallet: self.prioritized_addresses = d.get('prioritized_addresses',[]) self.expert_mode = d.get('expert_mode',False) self.gap_limit = d.get('gap_limit',5) + self.debug_server = d.get('debug_server',True) except: raise BaseException("cannot read wallet file")