Browse Source

CLI: properly auto-upgrade storage when needed even if storage-encrypted

previously commands would error if user had an encrypted storage that needed upgrading
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
01fc048484
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/json_db.py
  2. 5
      electrum/storage.py

8
electrum/json_db.py

@ -55,12 +55,12 @@ class TxFeesValue(NamedTuple):
class JsonDB(Logger):
def __init__(self, raw, *, manual_upgrades):
def __init__(self, raw, *, manual_upgrades: bool):
Logger.__init__(self)
self.lock = threading.RLock()
self.data = {}
self._modified = False
self.manual_upgrades = manual_upgrades
self._manual_upgrades = manual_upgrades
self._called_after_upgrade_tasks = False
if raw: # loading existing db
self.load_data(raw)
@ -142,12 +142,12 @@ class JsonDB(Logger):
if not isinstance(self.data, dict):
raise WalletFileException("Malformed wallet file (not dict)")
if not self.manual_upgrades and self.requires_split():
if not self._manual_upgrades and self.requires_split():
raise WalletFileException("This wallet has multiple accounts and must be split")
if not self.requires_upgrade():
self._after_upgrade_tasks()
elif not self.manual_upgrades:
elif not self._manual_upgrades:
self.upgrade()
def requires_split(self):

5
electrum/storage.py

@ -55,11 +55,12 @@ class StorageReadWriteError(Exception): pass
class WalletStorage(Logger):
def __init__(self, path, *, manual_upgrades=False):
def __init__(self, path, *, manual_upgrades: bool = False):
Logger.__init__(self)
self.lock = threading.RLock()
self.path = standardize_path(path)
self._file_exists = bool(self.path and os.path.exists(self.path))
self._manual_upgrades = manual_upgrades
DB_Class = JsonDB
self.logger.info(f"wallet path {self.path}")
@ -211,7 +212,7 @@ class WalletStorage(Logger):
s = None
self.pubkey = ec_key.get_public_key_hex()
s = s.decode('utf8')
self.db = JsonDB(s, manual_upgrades=True)
self.db = JsonDB(s, manual_upgrades=self._manual_upgrades)
self.load_plugins()
def encrypt_before_writing(self, plaintext: str) -> str:

Loading…
Cancel
Save