commit fd5f581128ef82d24014ab6f7dae6ccf26520c07
parent a7aa613b58d507ae1116573d72eb8d33ccc4af3b
Author: ThomasV <thomasv@gitorious>
Date: Mon, 19 Dec 2011 13:18:19 +0100
separate synchronize and update_tx_history
Diffstat:
2 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/client/electrum.py b/client/electrum.py
@@ -355,13 +355,16 @@ class Wallet:
def synchronize(self):
+ is_new = False
while True:
if self.change_addresses == []:
self.create_new_address2(True)
+ is_new = True
continue
a = self.change_addresses[-1]
if self.history.get(a):
self.create_new_address2(True)
+ is_new = True
else:
break
@@ -369,17 +372,19 @@ class Wallet:
while True:
if len(self.addresses) < n:
self.create_new_address2(False)
+ is_new = True
continue
if map( lambda a: self.history.get(a), self.addresses[-n:] ) == n*[[]]:
break
else:
self.create_new_address2(False)
+ is_new = True
- is_found = (len(self.change_addresses) > 1 ) or ( len(self.addresses) > self.gap_limit )
- if not is_found: return False
- # history and addressbook
- self.update_tx_history()
+ def is_found(self):
+ return (len(self.change_addresses) > 1 ) or ( len(self.addresses) > self.gap_limit )
+
+ def fill_addressbook(self):
for tx in self.tx_history.values():
if tx['value']<0:
for i in tx['outputs']:
@@ -387,7 +392,7 @@ class Wallet:
self.addressbook.append(i)
# redo labels
self.update_tx_labels()
- return True
+
def save(self):
s = {
@@ -528,6 +533,7 @@ class Wallet:
self.servers = map( lambda x:x[1], ast.literal_eval( self.request( repr ( ('peers', '' )))) )
def update(self):
+ is_new = False
blocks, changed_addresses = self.poll()
if blocks == -1: raise BaseException("session not found")
self.blocks = int(blocks)
@@ -536,9 +542,11 @@ class Wallet:
print "updating history for", addr
self.history[addr] = self.retrieve_history(addr)
self.status[addr] = blk_hash
+ is_new = True
- if changed_addresses:
+ if is_new:
self.synchronize()
+ self.update_tx_history()
self.save()
return True
else:
@@ -756,10 +764,11 @@ if __name__ == '__main__':
gap = raw_input("gap limit (default 5):")
if gap: wallet.gap_limit = int(gap)
print "recovering wallet..."
- r = wallet.synchronize()
- if r:
- print "recovery successful"
+ wallet.synchronize()
+ if wallet.is_found():
+ wallet.fill_addressbook()
wallet.save()
+ print "recovery successful"
else:
print "no wallet found"
else:
diff --git a/client/gui.py b/client/gui.py
@@ -134,9 +134,15 @@ def init_wallet(wallet):
def recover_thread( wallet, dialog ):
wallet.init_mpk( wallet.seed ) # not encrypted at this point
- wallet.is_found = wallet.synchronize()
- if wallet.is_found:
+ wallet.synchronize()
+
+ if wallet.is_found():
+ # history and addressbook
+ wallet.update_tx_history()
+ wallet.fill_addressbook()
+ print "recovery successful"
wallet.save()
+
gobject.idle_add( dialog.destroy )
thread.start_new_thread( recover_thread, ( wallet, dialog ) )
@@ -504,8 +510,8 @@ class BitcoinGUI:
get_servers_time = time.time()
self.period = 15 if self.wallet.use_http() else 5
- u = self.wallet.update()
- if u:
+ if self.wallet.update():
+ self.wallet.update_session()
gobject.idle_add( self.update_history_tab )
gobject.idle_add( self.update_receiving_tab )
# addressbook too...