improved logging
[electrum-server.git] / transports / native.py
index 1b6a6ec..2cc4313 100644 (file)
@@ -1,21 +1,26 @@
-import thread, threading, time, socket, traceback, ast
+import thread, threading, time, socket, traceback, ast, sys
 
 
+from processor import timestr, random_string
 
-def random_string(N):
-    import random, string
-    return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
 
-def timestr():
-    return time.strftime("[%d/%m/%Y-%H:%M:%S]")
+
+def new_to_old(s):
+    s = s.replace("'block_hash'", "'blk_hash'")
+    s = s.replace("'index'", "'pos'")
+    s = s.replace("'timestamp'", "'nTime'")
+    s = s.replace("'is_input'", "'is_in'")
+    s = s.replace("'raw_output_script'","'raw_scriptPubKey'")
+    return s
 
 
 class NativeServer(threading.Thread):
 
-    def __init__(self, shared, store, irc, banner, host, port):
+    def __init__(self, shared, abe, irc, banner, host, port):
         threading.Thread.__init__(self)
         self.banner = banner
-        self.store = store
+        self.abe = abe
+        self.store = abe.store
         self.irc = irc
         self.sessions = {}
         self.host = host
@@ -31,9 +36,9 @@ class NativeServer(threading.Thread):
         session['last_time'] = time.time()
         ret = {}
         k = 0
-        for addr in addresses:
+        for addr in addresses.keys():
             status = self.store.get_status( addr )
-            msg_id, last_status = addresses.get( addr )
+            msg_id, last_status = addresses[addr]
             if last_status != status:
                 addresses[addr] = msg_id, status
                 ret[addr] = status
@@ -50,7 +55,7 @@ class NativeServer(threading.Thread):
             self.sessions[session_id]['last_time'] = time.time()
             ret, addresses = self.modified_addresses(session)
             if ret: self.sessions[session_id]['addresses'] = addresses
-            return repr( (self.store.block_number,ret))
+            return repr( (self.abe.block_number,ret))
 
 
     def add_address_to_session(self, session_id, address):
@@ -74,7 +79,7 @@ class NativeServer(threading.Thread):
         """deprecated in 0.42, wad replaced by add_address_to_session"""
         self.sessions[session_id]['addresses'] = {}
         for a in addresses:
-            self.sessions[session_id]['addresses'][a] = ''
+            self.sessions[session_id]['addresses'][a] = ('','')
         self.sessions[session_id]['last_time'] = time.time()
         return 'ok'
 
@@ -115,7 +120,7 @@ class NativeServer(threading.Thread):
     def do_command(self, cmd, data, ipaddr):
 
         if cmd=='b':
-            out = "%d"%block_number
+            out = "%d"%self.abe.block_number
 
         elif cmd in ['session','new_session']:
             try:
@@ -155,6 +160,7 @@ class NativeServer(threading.Thread):
         elif cmd == 'h': 
             address = data
             out = repr( self.store.get_history( address ) )
+            out = new_to_old(out)
 
         elif cmd =='tx':
             out = self.store.send_tx(data)