Browse Source

check and fix history on startup

283
ThomasV 10 years ago
parent
commit
b0f7411a0a
  1. 25
      lib/wallet.py

25
lib/wallet.py

@ -183,6 +183,8 @@ class Abstract_Wallet(object):
self.transaction_lock = threading.Lock() self.transaction_lock = threading.Lock()
self.tx_event = threading.Event() self.tx_event = threading.Event()
self.check_history()
# save wallet type the first time # save wallet type the first time
if self.storage.get('wallet_type') is None: if self.storage.get('wallet_type') is None:
self.storage.put('wallet_type', self.wallet_type, True) self.storage.put('wallet_type', self.wallet_type, True)
@ -233,6 +235,25 @@ class Abstract_Wallet(object):
s.add(addr) s.add(addr)
self.tx_addr_hist[tx_hash] = s self.tx_addr_hist[tx_hash] = s
@profiler
def check_history(self):
save = False
for addr, hist in self.history.items():
if not self.is_mine(addr):
self.history.pop(addr)
save = True
continue
for tx_hash, tx_height in hist:
if tx_hash in self.pruned_txo.values() or self.txi.get(tx_hash) or self.txo.get(tx_hash):
continue
tx = self.transactions.get(tx_hash)
if tx is not None:
tx.deserialize()
self.add_transaction(tx_hash, tx, tx_height)
if save:
self.storage.put('addr_history', self.history, True)
# wizard action # wizard action
def get_action(self): def get_action(self):
pass pass
@ -314,6 +335,10 @@ class Abstract_Wallet(object):
self.accounts[IMPORTED_ACCOUNT].add(address, pubkey, sec, password) self.accounts[IMPORTED_ACCOUNT].add(address, pubkey, sec, password)
self.save_accounts() self.save_accounts()
# force resynchronization, because we need to re-run add_transaction
if addr in self.history:
self.history.pop(addr)
if self.synchronizer: if self.synchronizer:
self.synchronizer.add(address) self.synchronizer.add(address)
return address return address

Loading…
Cancel
Save