Browse Source

walletDB: replace 'manual_upgrades' parameter with 'upgrade', with opposite semantics

master
ThomasV 2 years ago
parent
commit
68159b3ef6
  1. 2
      electrum/commands.py
  2. 10
      electrum/daemon.py
  3. 4
      electrum/gui/qml/qewalletdb.py
  4. 2
      electrum/gui/qt/__init__.py
  5. 2
      electrum/lnwatcher.py
  6. 12
      electrum/tests/test_storage_upgrade.py
  7. 10
      electrum/tests/test_wallet.py
  8. 6
      electrum/tests/test_wallet_vertical.py
  9. 6
      electrum/wallet.py
  10. 6
      electrum/wallet_db.py
  11. 2
      electrum/wizard.py
  12. 2
      run_electrum

2
electrum/commands.py

@ -241,7 +241,7 @@ class Commands:
@command('n')
async def load_wallet(self, wallet_path=None, password=None):
"""Open wallet in daemon"""
wallet = self.daemon.load_wallet(wallet_path, password, manual_upgrades=False)
wallet = self.daemon.load_wallet(wallet_path, password, upgrade=True)
if wallet is not None:
run_hook('load_wallet', wallet, None)
response = wallet is not None

10
electrum/daemon.py

@ -481,13 +481,13 @@ class Daemon(Logger):
return func_wrapper
@with_wallet_lock
def load_wallet(self, path, password, *, manual_upgrades=True) -> Optional[Abstract_Wallet]:
def load_wallet(self, path, password, *, upgrade=False) -> Optional[Abstract_Wallet]:
path = standardize_path(path)
wallet_key = self._wallet_key_from_path(path)
# wizard will be launched if we return
if wallet := self._wallets.get(wallet_key):
return wallet
wallet = self._load_wallet(path, password, manual_upgrades=manual_upgrades, config=self.config)
wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config)
if wallet is None:
return
wallet.start_network(self.network)
@ -500,7 +500,7 @@ class Daemon(Logger):
path,
password,
*,
manual_upgrades: bool = True,
upgrade: bool = False,
config: SimpleConfig,
) -> Optional[Abstract_Wallet]:
path = standardize_path(path)
@ -513,7 +513,7 @@ class Daemon(Logger):
storage.decrypt(password)
# read data, pass it to db
try:
db = WalletDB(storage.read(), storage=storage, manual_upgrades=manual_upgrades)
db = WalletDB(storage.read(), storage=storage, upgrade=upgrade)
except WalletRequiresSplit:
return
except WalletRequiresUpgrade:
@ -654,7 +654,7 @@ class Daemon(Logger):
# hard-to-understand bugs will follow...
if wallet is None:
try:
wallet = self._load_wallet(path, old_password, manual_upgrades=False, config=self.config)
wallet = self._load_wallet(path, old_password, upgrade=True, config=self.config)
except util.InvalidPassword:
pass
except Exception:

4
electrum/gui/qml/qewalletdb.py

@ -144,7 +144,7 @@ class QEWalletDB(QObject):
# FIXME hack... load both db and full wallet, just to tell if it has keystore pw.
# this also completely ignores db.requires_split(), db.get_action(), etc
try:
db = WalletDB(self._storage.read(), storage=self._storage, manual_upgrades=False)
db = WalletDB(self._storage.read(), storage=self._storage, upgrade=True)
except WalletRequiresSplit as e:
raise WalletFileException(_('This wallet requires to be split. This is currently not supported on mobile'))
wallet = Wallet(db, config=self._config)
@ -166,7 +166,7 @@ class QEWalletDB(QObject):
"""can raise WalletFileException"""
# needs storage accessible
try:
self._db = WalletDB(self._storage.read(), storage=self._storage, manual_upgrades=False)
self._db = WalletDB(self._storage.read(), storage=self._storage, upgrade=True)
except WalletRequiresSplit as e:
self._logger.warning('wallet requires split')
raise WalletFileException(_('This wallet needs splitting. This is not supported on mobile'))

2
electrum/gui/qt/__init__.py

@ -431,7 +431,7 @@ class ElectrumGui(BaseElectrumGui, Logger):
storage.decrypt(d['password'])
try:
db = WalletDB(storage.read(), storage=storage, manual_upgrades=True)
db = WalletDB(storage.read(), storage=storage, upgrade=True)
except WalletRequiresSplit as e:
try:
wizard.run_split(storage, e._split_data)

2
electrum/lnwatcher.py

@ -325,7 +325,7 @@ class WatchTower(LNWatcher):
LOGGING_SHORTCUT = 'W'
def __init__(self, network: 'Network'):
adb = AddressSynchronizer(WalletDB('', storage=None, manual_upgrades=False), network.config, name=self.diagnostic_name())
adb = AddressSynchronizer(WalletDB('', storage=None, upgrade=True), network.config, name=self.diagnostic_name())
adb.start_network(network)
LNWatcher.__init__(self, adb, network)
self.network = network

12
electrum/tests/test_storage_upgrade.py

@ -334,24 +334,24 @@ class TestStorageUpgrade(WalletTestCase):
try:
db = self._load_db_from_json_string(
wallet_json=wallet_json,
manual_upgrades=True)
upgrade=False)
except WalletRequiresUpgrade:
db = self._load_db_from_json_string(
wallet_json=wallet_json,
manual_upgrades=False)
upgrade=True)
await self._sanity_check_upgraded_db(db)
return db
else:
try:
db = self._load_db_from_json_string(
wallet_json=wallet_json,
manual_upgrades=True)
upgrade=False)
except WalletRequiresSplit as e:
split_data = e._split_data
self.assertEqual(accounts, len(split_data))
for item in split_data:
data = json.dumps(item)
new_db = WalletDB(data, storage=None, manual_upgrades=False)
new_db = WalletDB(data, storage=None, upgrade=True)
await self._sanity_check_upgraded_db(new_db)
async def _sanity_check_upgraded_db(self, db):
@ -359,6 +359,6 @@ class TestStorageUpgrade(WalletTestCase):
await wallet.stop()
@staticmethod
def _load_db_from_json_string(*, wallet_json, manual_upgrades):
db = WalletDB(wallet_json, storage=None, manual_upgrades=manual_upgrades)
def _load_db_from_json_string(*, wallet_json, upgrade):
db = WalletDB(wallet_json, storage=None, upgrade=upgrade)
return db

10
electrum/tests/test_wallet.py

@ -110,7 +110,7 @@ class FakeWallet:
def __init__(self, fiat_value):
super().__init__()
self.fiat_value = fiat_value
self.db = WalletDB('', storage=None, manual_upgrades=True)
self.db = WalletDB('', storage=None, upgrade=False)
self.adb = FakeADB()
self.db.transactions = self.db.verified_tx = {'abc':'Tx'}
@ -257,7 +257,7 @@ class TestWalletPassword(WalletTestCase):
async def test_update_password_of_imported_wallet(self):
wallet_str = '{"addr_history":{"1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr":[],"15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA":[],"1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6":[]},"addresses":{"change":[],"receiving":["1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr","1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6","15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA"]},"keystore":{"keypairs":{"0344b1588589958b0bcab03435061539e9bcf54677c104904044e4f8901f4ebdf5":"L2sED74axVXC4H8szBJ4rQJrkfem7UMc6usLCPUoEWxDCFGUaGUM","0389508c13999d08ffae0f434a085f4185922d64765c0bff2f66e36ad7f745cc5f":"L3Gi6EQLvYw8gEEUckmqawkevfj9s8hxoQDFveQJGZHTfyWnbk1U","04575f52b82f159fa649d2a4c353eb7435f30206f0a6cb9674fbd659f45082c37d559ffd19bea9c0d3b7dcc07a7b79f4cffb76026d5d4dff35341efe99056e22d2":"5JyVyXU1LiRXATvRTQvR9Kp8Rx1X84j2x49iGkjSsXipydtByUq"},"type":"imported"},"pruned_txo":{},"seed_version":13,"stored_height":-1,"transactions":{},"tx_fees":{},"txi":{},"txo":{},"use_encryption":false,"verified_tx3":{},"wallet_type":"standard","winpos-qt":[100,100,840,405]}'
storage = WalletStorage(self.wallet_path)
db = WalletDB(wallet_str, storage=storage, manual_upgrades=False)
db = WalletDB(wallet_str, storage=storage, upgrade=True)
wallet = Wallet(db, config=self.config)
wallet.check_password(None)
@ -273,7 +273,7 @@ class TestWalletPassword(WalletTestCase):
async def test_update_password_of_standard_wallet(self):
wallet_str = '''{"addr_history":{"12ECgkzK6gHouKAZ7QiooYBuk1CgJLJxes":[],"12iR43FPb5M7sw4Mcrr5y1nHKepg9EtZP1":[],"13HT1pfWctsSXVFzF76uYuVdQvcAQ2MAgB":[],"13kG9WH9JqS7hyCcVL1ssLdNv4aXocQY9c":[],"14Tf3qiiHJXStSU4KmienAhHfHq7FHpBpz":[],"14gmBxYV97mzYwWdJSJ3MTLbTHVegaKrcA":[],"15FGuHvRssu1r8fCw98vrbpfc3M4xs5FAV":[],"17oJzweA2gn6SDjsKgA9vUD5ocT1sSnr2Z":[],"18hNcSjZzRcRP6J2bfFRxp9UfpMoC4hGTv":[],"18n9PFxBjmKCGhd4PCDEEqYsi2CsnEfn2B":[],"19a98ZfEezDNbCwidVigV5PAJwrR2kw4Jz":[],"19z3j2ELqbg2pR87byCCt3BCyKR7rc3q8G":[],"1A3XSmvLQvePmvm7yctsGkBMX9ZKKXLrVq":[],"1CmhFe2BN1h9jheFpJf4v39XNPj8F9U6d":[],"1DuphhHUayKzbkdvjVjf5dtjn2ACkz4zEs":[],"1E4ygSNJpWL2uPXZHBptmU2LqwZTqb1Ado":[],"1GTDSjkVc9vaaBBBGNVqTANHJBcoT5VW9z":[],"1GWqgpThAuSq3tDg6uCoLQxPXQNnU8jZ52":[],"1GhmpwqSF5cqNgdr9oJMZx8dKxPRo4pYPP":[],"1J5TTUQKhwehEACw6Jjte1E22FVrbeDmpv":[],"1JWySzjzJhsETUUcqVZHuvQLA7pfFfmesb":[],"1KQHxcy3QUHAWMHKUtJjqD9cMKXcY2RTwZ":[],"1KoxZfc2KsgovjGDxwqanbFEA76uxgYH4G":[],"1KqVEPXdpbYvEbwsZcEKkrA4A2jsgj9hYN":[],"1N16yDSYe76c5A3CoVoWAKxHeAUc8Jhf9J":[],"1Pm8JBhzUJDqeQQKrmnop1Frr4phe1jbTt":[]},"addresses":{"change":["1GhmpwqSF5cqNgdr9oJMZx8dKxPRo4pYPP","1GTDSjkVc9vaaBBBGNVqTANHJBcoT5VW9z","15FGuHvRssu1r8fCw98vrbpfc3M4xs5FAV","1A3XSmvLQvePmvm7yctsGkBMX9ZKKXLrVq","19z3j2ELqbg2pR87byCCt3BCyKR7rc3q8G","1JWySzjzJhsETUUcqVZHuvQLA7pfFfmesb"],"receiving":["14gmBxYV97mzYwWdJSJ3MTLbTHVegaKrcA","13HT1pfWctsSXVFzF76uYuVdQvcAQ2MAgB","19a98ZfEezDNbCwidVigV5PAJwrR2kw4Jz","1J5TTUQKhwehEACw6Jjte1E22FVrbeDmpv","1Pm8JBhzUJDqeQQKrmnop1Frr4phe1jbTt","13kG9WH9JqS7hyCcVL1ssLdNv4aXocQY9c","1KQHxcy3QUHAWMHKUtJjqD9cMKXcY2RTwZ","12ECgkzK6gHouKAZ7QiooYBuk1CgJLJxes","12iR43FPb5M7sw4Mcrr5y1nHKepg9EtZP1","14Tf3qiiHJXStSU4KmienAhHfHq7FHpBpz","1KqVEPXdpbYvEbwsZcEKkrA4A2jsgj9hYN","17oJzweA2gn6SDjsKgA9vUD5ocT1sSnr2Z","1E4ygSNJpWL2uPXZHBptmU2LqwZTqb1Ado","18hNcSjZzRcRP6J2bfFRxp9UfpMoC4hGTv","1KoxZfc2KsgovjGDxwqanbFEA76uxgYH4G","18n9PFxBjmKCGhd4PCDEEqYsi2CsnEfn2B","1CmhFe2BN1h9jheFpJf4v39XNPj8F9U6d","1DuphhHUayKzbkdvjVjf5dtjn2ACkz4zEs","1GWqgpThAuSq3tDg6uCoLQxPXQNnU8jZ52","1N16yDSYe76c5A3CoVoWAKxHeAUc8Jhf9J"]},"keystore":{"seed":"cereal wise two govern top pet frog nut rule sketch bundle logic","type":"bip32","xprv":"xprv9s21ZrQH143K29XjRjUs6MnDB9wXjXbJP2kG1fnRk8zjdDYWqVkQYUqaDtgZp5zPSrH5PZQJs8sU25HrUgT1WdgsPU8GbifKurtMYg37d4v","xpub":"xpub661MyMwAqRbcEdcCXm1sTViwjBn28zK9kFfrp4C3JUXiW1sfP34f6HA45B9yr7EH5XGzWuTfMTdqpt9XPrVQVUdgiYb5NW9m8ij1FSZgGBF"},"pruned_txo":{},"seed_type":"standard","seed_version":13,"stored_height":-1,"transactions":{},"tx_fees":{},"txi":{},"txo":{},"use_encryption":false,"verified_tx3":{},"wallet_type":"standard","winpos-qt":[619,310,840,405]}'''
storage = WalletStorage(self.wallet_path)
db = WalletDB(wallet_str, storage=storage, manual_upgrades=False)
db = WalletDB(wallet_str, storage=storage, upgrade=True)
wallet = Wallet(db, config=self.config)
wallet.check_password(None)
@ -288,14 +288,14 @@ class TestWalletPassword(WalletTestCase):
async def test_update_password_with_app_restarts(self):
wallet_str = '{"addr_history":{"1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr":[],"15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA":[],"1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6":[]},"addresses":{"change":[],"receiving":["1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr","1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6","15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA"]},"keystore":{"keypairs":{"0344b1588589958b0bcab03435061539e9bcf54677c104904044e4f8901f4ebdf5":"L2sED74axVXC4H8szBJ4rQJrkfem7UMc6usLCPUoEWxDCFGUaGUM","0389508c13999d08ffae0f434a085f4185922d64765c0bff2f66e36ad7f745cc5f":"L3Gi6EQLvYw8gEEUckmqawkevfj9s8hxoQDFveQJGZHTfyWnbk1U","04575f52b82f159fa649d2a4c353eb7435f30206f0a6cb9674fbd659f45082c37d559ffd19bea9c0d3b7dcc07a7b79f4cffb76026d5d4dff35341efe99056e22d2":"5JyVyXU1LiRXATvRTQvR9Kp8Rx1X84j2x49iGkjSsXipydtByUq"},"type":"imported"},"pruned_txo":{},"seed_version":13,"stored_height":-1,"transactions":{},"tx_fees":{},"txi":{},"txo":{},"use_encryption":false,"verified_tx3":{},"wallet_type":"standard","winpos-qt":[100,100,840,405]}'
storage = WalletStorage(self.wallet_path)
db = WalletDB(wallet_str, storage=storage, manual_upgrades=False)
db = WalletDB(wallet_str, storage=storage, upgrade=True)
wallet = Wallet(db, config=self.config)
await wallet.stop()
storage = WalletStorage(self.wallet_path)
# if storage.is_encrypted():
# storage.decrypt(password)
db = WalletDB(storage.read(), storage=storage, manual_upgrades=False)
db = WalletDB(storage.read(), storage=storage, upgrade=True)
wallet = Wallet(db, config=self.config)
wallet.check_password(None)

6
electrum/tests/test_wallet_vertical.py

@ -51,7 +51,7 @@ class WalletIntegrityHelper:
@classmethod
def create_standard_wallet(cls, ks, *, config: SimpleConfig, gap_limit=None):
db = storage.WalletDB('', storage=None, manual_upgrades=False)
db = storage.WalletDB('', storage=None, upgrade=True)
db.put('keystore', ks.dump())
db.put('gap_limit', gap_limit or cls.gap_limit)
w = Standard_Wallet(db, config=config)
@ -60,7 +60,7 @@ class WalletIntegrityHelper:
@classmethod
def create_imported_wallet(cls, *, config: SimpleConfig, privkeys: bool):
db = storage.WalletDB('', storage=None, manual_upgrades=False)
db = storage.WalletDB('', storage=None, upgrade=True)
if privkeys:
k = keystore.Imported_KeyStore({})
db.put('keystore', k.dump())
@ -71,7 +71,7 @@ class WalletIntegrityHelper:
def create_multisig_wallet(cls, keystores: Sequence, multisig_type: str, *,
config: SimpleConfig, gap_limit=None):
"""Creates a multisig wallet."""
db = storage.WalletDB('', storage=None, manual_upgrades=True)
db = storage.WalletDB('', storage=None, upgrade=False)
for i, ks in enumerate(keystores):
cosigner_index = i + 1
db.put('x%d/' % cosigner_index, ks.dump())

6
electrum/wallet.py

@ -408,7 +408,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
new_storage._encryption_version = self.storage._encryption_version
new_storage.pubkey = self.storage.pubkey
new_db = WalletDB(self.db.dump(), storage=new_storage, manual_upgrades=False)
new_db = WalletDB(self.db.dump(), storage=new_storage, upgrade=True)
if self.lnworker:
channel_backups = new_db.get_dict('imported_channel_backups')
for chan_id, chan in self.lnworker.channels.items():
@ -3709,7 +3709,7 @@ def create_new_wallet(*, path, config: SimpleConfig, passphrase=None, password=N
storage = WalletStorage(path)
if storage.file_exists():
raise Exception("Remove the existing wallet first!")
db = WalletDB('', storage=storage, manual_upgrades=False)
db = WalletDB('', storage=storage, upgrade=True)
seed = Mnemonic('en').make_seed(seed_type=seed_type)
k = keystore.from_seed(seed, passphrase)
@ -3748,7 +3748,7 @@ def restore_wallet_from_text(
raise Exception("Remove the existing wallet first!")
if encrypt_file is None:
encrypt_file = True
db = WalletDB('', storage=storage, manual_upgrades=False)
db = WalletDB('', storage=storage, upgrade=True)
text = text.strip()
if keystore.is_address_list(text):
wallet = Imported_Wallet(db, config=config)

6
electrum/wallet_db.py

@ -1164,8 +1164,8 @@ class WalletDBUpgrader(Logger):
class WalletDB(JsonDB):
def __init__(self, s, *, storage=None, manual_upgrades=True):
self._upgrade = not manual_upgrades
def __init__(self, s, *, storage=None, upgrade=False):
self._upgrade = upgrade
JsonDB.__init__(self, s, storage, encoder=MyEncoder)
# create pointers
self.load_transactions()
@ -1634,7 +1634,7 @@ class WalletDB(JsonDB):
for data in split_data:
path = root_path + '.' + data['suffix']
item_storage = WalletStorage(path)
db = WalletDB(json.dumps(data), storage=item_storage, manual_upgrades=False)
db = WalletDB(json.dumps(data), storage=item_storage, upgrades=True)
db.write()
file_list.append(path)
return file_list

2
electrum/wizard.py

@ -587,7 +587,7 @@ class NewWalletWizard(AbstractWizard):
enc_version = StorageEncryptionVersion.XPUB_PASSWORD
storage.set_password(data['password'], enc_version=enc_version)
db = WalletDB('', storage=storage, manual_upgrades=False)
db = WalletDB('', storage=storage, upgrade=True)
db.set_keystore_encryption(bool(data['password']) and data['encrypt'])
db.put('wallet_type', data['wallet_type'])

2
run_electrum

@ -227,7 +227,7 @@ async def run_offline_command(config, config_options, plugins: 'Plugins'):
password = get_password_for_hw_device_encrypted_storage(plugins)
config_options['password'] = password
storage.decrypt(password)
db = WalletDB(storage.read(), storage=storage, manual_upgrades=False)
db = WalletDB(storage.read(), storage=storage, upgrade=True)
wallet = Wallet(db, config=config)
config_options['wallet'] = wallet
else:

Loading…
Cancel
Save