pass username to got_response for logging
authorForrest Voight <forrest@forre.st>
Sat, 20 Aug 2011 06:32:50 +0000 (02:32 -0400)
committerForrest Voight <forrest@forre.st>
Sat, 20 Aug 2011 06:32:50 +0000 (02:32 -0400)
p2pool/main.py
p2pool/worker_interface.py

index 794c9a2..19cd5c4 100644 (file)
@@ -418,7 +418,7 @@ def main(args):
         my_shares = set()
         times = {}
         
-        def got_response(data):
+        def got_response(data, user):
             try:
                 # match up with transactions
                 header = bitcoin.getwork.decode_data(data)
@@ -443,7 +443,7 @@ def main(args):
                     return False
                 share = p2pool.Share.from_block(block)
                 my_shares.add(share.hash)
-                print 'GOT SHARE! %s prev %s age %.2fs' % (p2pool.format_hash(share.hash), p2pool.format_hash(share.previous_hash), time.time() - times[share.nonce]) + (' DEAD ON ARRIVAL' if share.previous_hash != current_work.value['best_share_hash'] else '')
+                print 'GOT SHARE! %s %s prev %s age %.2fs' % (user, p2pool.format_hash(share.hash), p2pool.format_hash(share.previous_hash), time.time() - times[share.nonce]) + (' DEAD ON ARRIVAL' if share.previous_hash != current_work.value['best_share_hash'] else '')
                 good = share.previous_hash == current_work.value['best_share_hash']
                 # maybe revert back to tracker being non-blocking so 'good' can be more accurate?
                 p2p_shares([share])
index 4a2273c..673fa85 100644 (file)
@@ -12,9 +12,17 @@ from p2pool import data as p2pool_data
 from p2pool.util import jsonrpc, deferred_resource, variable
 from p2pool.bitcoin import data as bitcoin_data
 
+def get_username(request):
+    try:
+        return base64.b64decode(request.getHeader('Authorization').split(' ', 1)[1]).split(':')[0]
+    except: # XXX
+        return None
+
 def get_payout_script(request, net):
+    user = get_username(request)
+    if user is None:
+        return None
     try:
-        user = base64.b64decode(request.getHeader('Authorization').split(' ', 1)[1]).split(':')[0]
         return bitcoin_data.pubkey_hash_to_script2(bitcoin_data.address_to_pubkey_hash(user, net))
     except: # XXX blah
         return None
@@ -106,7 +114,7 @@ class WorkerInterface(jsonrpc.Server):
         request.setHeader('X-Long-Polling', '/long-polling')
         
         if data is not None:
-            defer.returnValue(self.response_callback(data))
+            defer.returnValue(self.response_callback(data, get_username(request)))
         
         defer.returnValue((yield self.getwork(request)))
     rpc_getwork.takes_request = True