mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
json_db: exempt keystore from StoredDict conversion
The keystore logic would need to be significantly changed to nicely
interoperate with StoredDict/json_db logic.
(just see KeyStore.__init__() and KeyStore.dump())
For now we exempt the keystore from the recursive StoredDict conversion, as
it is a smaller change that is also easier to review for correctness.
fixes #6066
fixes #6401
also reverts 2d3c2eeea9
(which was an even hackier workaround for #6066)
This commit is contained in:
parent
8dc3fadd13
commit
a7199696d3
5 changed files with 14 additions and 4 deletions
|
@ -103,6 +103,7 @@ class StoredDict(dict):
|
||||||
elif isinstance(v, dict):
|
elif isinstance(v, dict):
|
||||||
if self.db:
|
if self.db:
|
||||||
v = self.db._convert_dict(self.path, key, v)
|
v = self.db._convert_dict(self.path, key, v)
|
||||||
|
if not self.db or self.db._should_convert_to_stored_dict(key):
|
||||||
v = StoredDict(v, self.db, self.path + [key])
|
v = StoredDict(v, self.db, self.path + [key])
|
||||||
# convert_value is called depth-first
|
# convert_value is called depth-first
|
||||||
if isinstance(v, dict) or isinstance(v, str):
|
if isinstance(v, dict) or isinstance(v, str):
|
||||||
|
@ -194,3 +195,6 @@ class JsonDB(Logger):
|
||||||
@locked
|
@locked
|
||||||
def dump(self):
|
def dump(self):
|
||||||
return json.dumps(self.data, indent=4, sort_keys=True, cls=JsonDBJsonEncoder)
|
return json.dumps(self.data, indent=4, sort_keys=True, cls=JsonDBJsonEncoder)
|
||||||
|
|
||||||
|
def _should_convert_to_stored_dict(self, key) -> bool:
|
||||||
|
return True
|
||||||
|
|
|
@ -894,7 +894,6 @@ def hardware_keystore(d) -> Hardware_KeyStore:
|
||||||
|
|
||||||
def load_keystore(db: 'WalletDB', name: str) -> KeyStore:
|
def load_keystore(db: 'WalletDB', name: str) -> KeyStore:
|
||||||
d = db.get(name, {})
|
d = db.get(name, {})
|
||||||
d = dict(d) # convert to dict from StoredDict (see #6066)
|
|
||||||
t = d.get('type')
|
t = d.get('type')
|
||||||
if not t:
|
if not t:
|
||||||
raise WalletFileException(
|
raise WalletFileException(
|
||||||
|
|
|
@ -521,7 +521,7 @@ class BitBox02_KeyStore(Hardware_KeyStore):
|
||||||
device = "BitBox02"
|
device = "BitBox02"
|
||||||
plugin: "BitBox02Plugin"
|
plugin: "BitBox02Plugin"
|
||||||
|
|
||||||
def __init__(self, d: StoredDict):
|
def __init__(self, d: dict):
|
||||||
super().__init__(d)
|
super().__init__(d)
|
||||||
self.force_watching_only = False
|
self.force_watching_only = False
|
||||||
self.ux_busy = False
|
self.ux_busy = False
|
||||||
|
|
|
@ -255,7 +255,6 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
||||||
self.force_watching_only = False
|
self.force_watching_only = False
|
||||||
self.signing = False
|
self.signing = False
|
||||||
self.cfg = d.get('cfg', {'mode': 0})
|
self.cfg = d.get('cfg', {'mode': 0})
|
||||||
self.cfg = dict(self.cfg) # convert to dict from StoredDict (see #6066)
|
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
obj = Hardware_KeyStore.dump(self)
|
obj = Hardware_KeyStore.dump(self)
|
||||||
|
|
|
@ -1211,6 +1211,14 @@ class WalletDB(JsonDB):
|
||||||
v = Outpoint(**v)
|
v = Outpoint(**v)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
def _should_convert_to_stored_dict(self, key) -> bool:
|
||||||
|
if key == 'keystore':
|
||||||
|
return False
|
||||||
|
multisig_keystore_names = [('x%d/' % i) for i in range(1, 16)]
|
||||||
|
if key in multisig_keystore_names:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def write(self, storage: 'WalletStorage'):
|
def write(self, storage: 'WalletStorage'):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._write(storage)
|
self._write(storage)
|
||||||
|
|
Loading…
Add table
Reference in a new issue