Browse Source

use print_error

283
ThomasV 12 years ago
parent
commit
3216c0467d
  1. 9
      lib/interface.py
  2. 17
      lib/verifier.py

9
lib/interface.py

@ -81,7 +81,7 @@ class Interface(threading.Thread):
error = c.get('error') error = c.get('error')
if error: if error:
print "received error:", c print_error("received error:", c)
return return
if msg_id is not None: if msg_id is not None:
@ -112,8 +112,8 @@ class Interface(threading.Thread):
channel = k channel = k
break break
else: else:
print "received unexpected notification", method, params print_error( "received unexpected notification", method, params)
print self.subscriptions print_error( self.subscriptions )
return return
response_queue = self.responses[channel] response_queue = self.responses[channel]
@ -259,7 +259,6 @@ class Interface(threading.Thread):
while self.is_connected: while self.is_connected:
try: msg = self.s.recv(1024) try: msg = self.s.recv(1024)
except socket.timeout: except socket.timeout:
print "timeout"
# ping the server with server.version, as a real ping does not exist yet # ping the server with server.version, as a real ping does not exist yet
self.send([('server.version', [ELECTRUM_VERSION])]) self.send([('server.version', [ELECTRUM_VERSION])])
continue continue
@ -301,7 +300,7 @@ class Interface(threading.Thread):
out = out[sent:] out = out[sent:]
except: except:
# this happens when we get disconnected # this happens when we get disconnected
print "Not connected, cannot send" print_error( "Not connected, cannot send" )
return None return None
return ids return ids

17
lib/verifier.py

@ -18,7 +18,7 @@
import threading, time, Queue, os, sys import threading, time, Queue, os, sys
from util import user_dir from util import user_dir, print_error
from bitcoin import * from bitcoin import *
@ -77,7 +77,7 @@ class WalletVerifier(threading.Thread):
break break
else: else:
all_chunks = True all_chunks = True
print "all chunks" print_error("downloaded all chunks")
# request missing tx merkle # request missing tx merkle
for tx in self.transactions: for tx in self.transactions:
@ -98,7 +98,7 @@ class WalletVerifier(threading.Thread):
# request previous header # request previous header
i = header.get('block_height') - 1 i = header.get('block_height') - 1
if i not in requested_headers: if i not in requested_headers:
print "requesting header", i print_error("requesting header %d"%i)
self.interface.send([ ('blockchain.block.get_header',[i])], 'verifier') self.interface.send([ ('blockchain.block.get_header',[i])], 'verifier')
requested_headers.append(i) requested_headers.append(i)
# no point continuing # no point continuing
@ -154,7 +154,7 @@ class WalletVerifier(threading.Thread):
if header: if header:
assert header.get('merkle_root') == self.merkle_roots[tx_hash] assert header.get('merkle_root') == self.merkle_roots[tx_hash]
self.verified_tx[tx_hash] = tx_height self.verified_tx[tx_hash] = tx_height
print "verified", tx_hash print_error("verified %s"%tx_hash)
self.config.set_key('verified_tx', self.verified_tx, True) self.config.set_key('verified_tx', self.verified_tx, True)
@ -162,7 +162,7 @@ class WalletVerifier(threading.Thread):
data = hexdata.decode('hex') data = hexdata.decode('hex')
height = index*2016 height = index*2016
num = len(data)/80 num = len(data)/80
print "validating headers", height, num print_error("validating headers %d"%height)
if index == 0: if index == 0:
previous_hash = ("0"*64) previous_hash = ("0"*64)
@ -196,7 +196,7 @@ class WalletVerifier(threading.Thread):
prev_header = self.read_header(height -1) prev_header = self.read_header(height -1)
if not prev_header: if not prev_header:
print "no previous header", height print_error("no previous header: %s"%height)
return False return False
#prev_hash = prev_header.get('block_height') #prev_hash = prev_header.get('block_height')
@ -208,12 +208,12 @@ class WalletVerifier(threading.Thread):
assert bits == header.get('bits') assert bits == header.get('bits')
assert eval('0x'+_hash) < target assert eval('0x'+_hash) < target
except: except:
print "verify header failed", header print_error("verify header failed"+ repr(header))
# this can be caused by a reorg. returning False will request the previous header. # this can be caused by a reorg. returning False will request the previous header.
return False return False
self.save_header(header) self.save_header(header)
print "verify header: ok", height print_error("verify header: ok %d"%height)
return True return True
@ -337,6 +337,5 @@ class WalletVerifier(threading.Thread):
i += 1 i += 1
new_bits = c + MM * i new_bits = c + MM * i
# print "%3d"%index, "%8x"%bits, "%64X"%new_target, hex(c)[2:].upper(), hex(new_bits)
return new_bits, new_target return new_bits, new_target

Loading…
Cancel
Save