self-synchronizing wallet
This commit is contained in:
parent
3333db56c1
commit
5af496ceb5
|
@ -341,40 +341,39 @@ class Wallet:
|
||||||
self.change_addresses.append(address)
|
self.change_addresses.append(address)
|
||||||
else:
|
else:
|
||||||
self.addresses.append(address)
|
self.addresses.append(address)
|
||||||
|
|
||||||
|
# updates
|
||||||
|
print address
|
||||||
|
self.history[address] = h = self.retrieve_history(address)
|
||||||
|
self.status[address] = h[-1]['blk_hash'] if h else None
|
||||||
self.save()
|
self.save()
|
||||||
return address
|
return address
|
||||||
|
|
||||||
def recover(self):
|
|
||||||
# todo: recover receiving addresses from tx
|
def synchronize(self):
|
||||||
is_found = False
|
|
||||||
while True:
|
while True:
|
||||||
addr = self.create_new_address2(True)
|
if self.change_addresses == []:
|
||||||
self.history[addr] = h = self.retrieve_history(addr)
|
self.create_new_address2(True)
|
||||||
self.status[addr] = h[-1]['blk_hash'] if h else None
|
continue
|
||||||
print "recovering", addr
|
a = self.change_addresses[-1]
|
||||||
if self.status[addr] is not None:
|
if self.history.get(a):
|
||||||
is_found = True
|
self.create_new_address2(True)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
num_gap = 0
|
|
||||||
while True:
|
|
||||||
addr = self.create_new_address2(False)
|
|
||||||
self.history[addr] = h = self.retrieve_history(addr)
|
|
||||||
self.status[addr] = h[-1]['blk_hash'] if h else None
|
|
||||||
print "recovering", addr
|
|
||||||
if self.status[addr] is None:
|
|
||||||
num_gap += 1
|
|
||||||
if num_gap == self.gap_limit: break
|
|
||||||
else:
|
|
||||||
is_found = True
|
|
||||||
num_gap = 0
|
|
||||||
|
|
||||||
if not is_found: return False
|
|
||||||
|
|
||||||
# remove limit-1 addresses.
|
|
||||||
n = self.gap_limit
|
n = self.gap_limit
|
||||||
self.addresses = self.addresses[:-n]
|
while True:
|
||||||
|
if len(self.addresses) < n:
|
||||||
|
self.create_new_address2(False)
|
||||||
|
continue
|
||||||
|
if map( lambda a: self.history.get(a), self.addresses[-n:] ) == n*[[]]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.create_new_address2(False)
|
||||||
|
|
||||||
|
is_found = (len(self.change_addresses) > 1 ) or ( len(self.addresses) > self.gap_limit )
|
||||||
|
if not is_found: return False
|
||||||
|
|
||||||
# history and addressbook
|
# history and addressbook
|
||||||
self.update_tx_history()
|
self.update_tx_history()
|
||||||
|
@ -536,8 +535,10 @@ See the release notes for more information.""",1)
|
||||||
print "updating history for", addr
|
print "updating history for", addr
|
||||||
self.history[addr] = self.retrieve_history(addr)
|
self.history[addr] = self.retrieve_history(addr)
|
||||||
self.status[addr] = blk_hash
|
self.status[addr] = blk_hash
|
||||||
self.update_tx_history()
|
|
||||||
if changed_addresses:
|
if changed_addresses:
|
||||||
|
self.synchronize()
|
||||||
|
self.save()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -755,7 +756,7 @@ if __name__ == '__main__':
|
||||||
gap = raw_input("gap limit (default 5):")
|
gap = raw_input("gap limit (default 5):")
|
||||||
if gap: wallet.gap_limit = int(gap)
|
if gap: wallet.gap_limit = int(gap)
|
||||||
print "recovering wallet..."
|
print "recovering wallet..."
|
||||||
r = wallet.recover()
|
r = wallet.synchronize()
|
||||||
if r:
|
if r:
|
||||||
print "recovery successful"
|
print "recovery successful"
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
|
@ -514,8 +514,10 @@ class BitcoinGUI:
|
||||||
self.period = 15 if self.wallet.use_http() else 5
|
self.period = 15 if self.wallet.use_http() else 5
|
||||||
u = self.wallet.update()
|
u = self.wallet.update()
|
||||||
if u:
|
if u:
|
||||||
self.wallet.save()
|
|
||||||
gobject.idle_add( self.update_history_tab )
|
gobject.idle_add( self.update_history_tab )
|
||||||
|
gobject.idle_add( self.update_receiving_tab )
|
||||||
|
# addressbook too...
|
||||||
|
|
||||||
time.sleep(self.period)
|
time.sleep(self.period)
|
||||||
except BaseException:
|
except BaseException:
|
||||||
print "starting new session"
|
print "starting new session"
|
||||||
|
@ -823,10 +825,11 @@ class BitcoinGUI:
|
||||||
scroll.add(treeview)
|
scroll.add(treeview)
|
||||||
|
|
||||||
hbox = gtk.HBox()
|
hbox = gtk.HBox()
|
||||||
button = gtk.Button("New address")
|
if not is_recv:
|
||||||
button.connect("clicked", self.newaddress_dialog, is_recv)
|
button = gtk.Button("New address")
|
||||||
button.show()
|
button.connect("clicked", self.newaddress_dialog, is_recv)
|
||||||
hbox.pack_start(button,False)
|
button.show()
|
||||||
|
hbox.pack_start(button,False)
|
||||||
|
|
||||||
def showqrcode(w, treeview, liststore):
|
def showqrcode(w, treeview, liststore):
|
||||||
path, col = treeview.get_cursor()
|
path, col = treeview.get_cursor()
|
||||||
|
@ -922,7 +925,7 @@ class BitcoinGUI:
|
||||||
for item in h:
|
for item in h:
|
||||||
if not item['is_in'] : n=n+1
|
if not item['is_in'] : n=n+1
|
||||||
tx = "None" if n==0 else "%d"%n
|
tx = "None" if n==0 else "%d"%n
|
||||||
self.recv_list.prepend((address, label, tx ))
|
self.recv_list.append((address, label, tx ))
|
||||||
|
|
||||||
def update_sending_tab(self):
|
def update_sending_tab(self):
|
||||||
# detect addresses that are not mine in history, add them here...
|
# detect addresses that are not mine in history, add them here...
|
||||||
|
|
Loading…
Reference in New Issue