Browse Source

init headers file

283
ThomasV 12 years ago
parent
commit
e39a5c9609
  1. 37
      lib/verifier.py
  2. 4
      lib/wallet.py

37
lib/verifier.py

@ -43,6 +43,7 @@ class WalletVerifier(threading.Thread):
self.pending_headers = [] # headers that have not been verified self.pending_headers = [] # headers that have not been verified
self.height = 0 self.height = 0
self.local_height = 0 self.local_height = 0
self.init_headers_file()
self.set_local_height() self.set_local_height()
def get_confirmations(self, tx): def get_confirmations(self, tx):
@ -76,7 +77,7 @@ class WalletVerifier(threading.Thread):
min_index = (self.local_height + 1)/2016 min_index = (self.local_height + 1)/2016
max_index = (self.height + 1)/2016 max_index = (self.height + 1)/2016
for i in range(min_index, max_index + 1): for i in range(min_index, max_index + 1):
# print "requesting chunk", i print_error( "requesting chunk", i )
self.interface.send([ ('blockchain.block.get_chunk',[i])], 'verifier') self.interface.send([ ('blockchain.block.get_chunk',[i])], 'verifier')
requested_chunks.append(i) requested_chunks.append(i)
break break
@ -108,8 +109,10 @@ class WalletVerifier(threading.Thread):
requested_headers.append(i) requested_headers.append(i)
# no point continuing # no point continuing
break break
for header in done: self.pending_headers.remove(header) if done:
self.interface.trigger_callback('updated') self.interface.trigger_callback('updated')
for header in done:
self.pending_headers.remove(header)
try: try:
r = self.interface.get_response('verifier',timeout=1) r = self.interface.get_response('verifier',timeout=1)
@ -143,8 +146,6 @@ class WalletVerifier(threading.Thread):
self.pending_headers.sort(key=lambda x: x.get('block_height')) self.pending_headers.sort(key=lambda x: x.get('block_height'))
# print "pending headers", map(lambda x: x.get('block_height'), self.pending_headers) # print "pending headers", map(lambda x: x.get('block_height'), self.pending_headers)
self.interface.trigger_callback('updated')
def verify_merkle(self, tx_hash, result): def verify_merkle(self, tx_hash, result):
@ -157,6 +158,8 @@ class WalletVerifier(threading.Thread):
self.verified_tx[tx_hash] = tx_height self.verified_tx[tx_hash] = tx_height
print_error("verified %s"%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)
self.interface.trigger_callback('updated')
def verify_chunk(self, index, hexdata): def verify_chunk(self, index, hexdata):
data = hexdata.decode('hex') data = hexdata.decode('hex')
@ -261,20 +264,22 @@ class WalletVerifier(threading.Thread):
if not os.path.exists( wdir ): os.mkdir(wdir) if not os.path.exists( wdir ): os.mkdir(wdir)
return os.path.join( wdir, 'blockchain_headers') return os.path.join( wdir, 'blockchain_headers')
def save_chunk(self, index, chunk): def init_headers_file(self):
filename = self.path() filename = self.path()
if os.path.exists(filename): if os.path.exists(filename):
f = open(filename,'rb+') return
src = os.path.join(appdata_dir(), 'blockchain_headers')
if os.path.exists(src):
# copy it from appdata dir
print_error( "copying headers to", filename )
shutil.copy(src, filename)
else: else:
src = os.path.join(appdata_dir(),'blockchain_headers') print_error( "creating headers file", filename )
if os.path.exists(src): open(filename,'wb+').close()
# copy it from appdata dir
print_error( "copying headers to", filename ) def save_chunk(self, index, chunk):
shutil.copy(src, filename) filename = self.path()
f = open(filename,'rb+') f = open(filename,'rb+')
else:
print_error( "creating file", filename )
f = open(filename,'wb+')
f.seek(index*2016*80) f.seek(index*2016*80)
h = f.write(chunk) h = f.write(chunk)
f.close() f.close()

4
lib/wallet.py

@ -936,6 +936,7 @@ class WalletSynchronizer(threading.Thread):
def run(self): def run(self):
requested_tx = [] requested_tx = []
missing_tx = [] missing_tx = []
requested_histories = {}
# request any missing transactions # request any missing transactions
for history in self.wallet.history.values(): for history in self.wallet.history.values():
@ -982,7 +983,8 @@ class WalletSynchronizer(threading.Thread):
addr = params[0] addr = params[0]
if self.wallet.get_status(addr) != result: if self.wallet.get_status(addr) != result:
self.interface.send([('blockchain.address.get_history', [addr])], 'synchronizer') self.interface.send([('blockchain.address.get_history', [addr])], 'synchronizer')
requested_histories[addr] = result
elif method == 'blockchain.address.get_history': elif method == 'blockchain.address.get_history':
addr = params[0] addr = params[0]
hist = [] hist = []

Loading…
Cancel
Save