commit 597295e35931f001dce80cc30937911d6b2229b0
parent 801d3113ab44789c70a896b1865a133c0af3675f
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 19 Jul 2018 18:16:23 +0200
address_synchronizer fixes
is_mine: wallet expects get_address_index to work
imported wallets: history did not include addr keys after creation
deterministic wallets: get_addresses() should be sorted in derivation order
Diffstat:
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -67,6 +67,10 @@ class AddressSynchronizer(PrintError):
self.unverified_tx = defaultdict(int)
# true when synchronized
self.up_to_date = False
+
+ self.load_and_cleanup()
+
+ def load_and_cleanup(self):
self.load_transactions()
self.load_local_history()
self.check_history()
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -169,6 +169,7 @@ class Abstract_Wallet(AddressSynchronizer):
def __init__(self, storage):
AddressSynchronizer.__init__(self, storage)
+
self.electrum_version = ELECTRUM_VERSION
# saved fields
self.use_change = storage.get('use_change', True)
@@ -178,10 +179,6 @@ class Abstract_Wallet(AddressSynchronizer):
self.fiat_value = storage.get('fiat_value', {})
self.receive_requests = storage.get('payment_requests', {})
- self.load_keystore()
- self.load_addresses()
- self.test_addresses_sanity()
-
# save wallet type the first time
if self.storage.get('wallet_type') is None:
self.storage.put('wallet_type', self.wallet_type)
@@ -192,6 +189,12 @@ class Abstract_Wallet(AddressSynchronizer):
self.coin_price_cache = {}
+ def load_and_cleanup(self):
+ self.load_keystore()
+ self.load_addresses()
+ self.test_addresses_sanity()
+ super().load_and_cleanup()
+
def diagnostic_name(self):
return self.basename()
@@ -268,6 +271,15 @@ class Abstract_Wallet(AddressSynchronizer):
except:
return
+ def is_mine(self, address):
+ if not super().is_mine(address):
+ return False
+ try:
+ self.get_address_index(address)
+ except KeyError:
+ return False
+ return True
+
def is_change(self, address):
if not self.is_mine(address):
return False
@@ -1218,9 +1230,9 @@ class Imported_Wallet(Simple_Wallet):
if address in self.addresses:
return ''
self.addresses[address] = {}
- self.storage.put('addresses', self.addresses)
- self.storage.write()
self.add_address(address)
+ self.save_addresses()
+ self.save_transactions(write=True)
return address
def delete_address(self, address):
@@ -1268,7 +1280,7 @@ class Imported_Wallet(Simple_Wallet):
else:
self.keystore.delete_imported_key(pubkey)
self.save_keystore()
- self.storage.put('addresses', self.addresses)
+ self.save_addresses()
self.storage.write()
@@ -1296,9 +1308,9 @@ class Imported_Wallet(Simple_Wallet):
raise NotImplementedError(txin_type)
self.addresses[addr] = {'type':txin_type, 'pubkey':pubkey, 'redeem_script':redeem_script}
self.save_keystore()
- self.save_addresses()
- self.storage.write()
self.add_address(addr)
+ self.save_addresses()
+ self.save_transactions(write=True)
return addr
def get_redeem_script(self, address):
@@ -1337,6 +1349,13 @@ class Deterministic_Wallet(Abstract_Wallet):
def has_seed(self):
return self.keystore.has_seed()
+ def get_addresses(self):
+ # overloaded so that addresses are ordered based on derivation
+ out = []
+ out += self.get_receiving_addresses()
+ out += self.get_change_addresses()
+ return out
+
def get_receiving_addresses(self):
return self.receiving_addresses