Browse Source

wallet_db: put 'seed_type' into keystores (incl db upgrade)

patch-4
SomberNight 4 years ago
parent
commit
7b7bba2299
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/gui/qt/main_window.py
  2. 9
      electrum/keystore.py
  3. 26
      electrum/wallet_db.py

7
electrum/gui/qt/main_window.py

@ -2400,7 +2400,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
wallet_type = self.wallet.db.get('wallet_type', '') wallet_type = self.wallet.db.get('wallet_type', '')
if self.wallet.is_watching_only(): if self.wallet.is_watching_only():
wallet_type += ' [{}]'.format(_('watching-only')) wallet_type += ' [{}]'.format(_('watching-only'))
seed_available = _('True') if self.wallet.has_seed() else _('False') seed_available = _('False')
if self.wallet.has_seed():
seed_available = _('True')
ks = self.wallet.keystore
assert isinstance(ks, keystore.Deterministic_KeyStore)
seed_available += f" ({ks.get_seed_type()})"
keystore_types = [k.get_type_text() for k in self.wallet.get_keystores()] keystore_types = [k.get_type_text() for k in self.wallet.get_keystores()]
grid = QGridLayout() grid = QGridLayout()
basename = os.path.basename(self.wallet.storage.path) basename = os.path.basename(self.wallet.storage.path)

9
electrum/keystore.py

@ -282,8 +282,9 @@ class Deterministic_KeyStore(Software_KeyStore):
def __init__(self, d): def __init__(self, d):
Software_KeyStore.__init__(self, d) Software_KeyStore.__init__(self, d)
self.seed = d.get('seed', '') self.seed = d.get('seed', '') # only electrum seeds
self.passphrase = d.get('passphrase', '') self.passphrase = d.get('passphrase', '')
self._seed_type = d.get('seed_type', None) # only electrum seeds
def is_deterministic(self): def is_deterministic(self):
return True return True
@ -297,11 +298,16 @@ class Deterministic_KeyStore(Software_KeyStore):
d['seed'] = self.seed d['seed'] = self.seed
if self.passphrase: if self.passphrase:
d['passphrase'] = self.passphrase d['passphrase'] = self.passphrase
if self._seed_type:
d['seed_type'] = self._seed_type
return d return d
def has_seed(self): def has_seed(self):
return bool(self.seed) return bool(self.seed)
def get_seed_type(self) -> Optional[str]:
return self._seed_type
def is_watching_only(self): def is_watching_only(self):
return not self.has_seed() return not self.has_seed()
@ -313,6 +319,7 @@ class Deterministic_KeyStore(Software_KeyStore):
if self.seed: if self.seed:
raise Exception("a seed exists") raise Exception("a seed exists")
self.seed = self.format_seed(seed) self.seed = self.format_seed(seed)
self._seed_type = seed_type(seed) or None
def get_seed(self, password): def get_seed(self, password):
if not self.has_seed(): if not self.has_seed():

26
electrum/wallet_db.py

@ -53,7 +53,7 @@ if TYPE_CHECKING:
OLD_SEED_VERSION = 4 # electrum versions < 2.0 OLD_SEED_VERSION = 4 # electrum versions < 2.0
NEW_SEED_VERSION = 11 # electrum versions >= 2.0 NEW_SEED_VERSION = 11 # electrum versions >= 2.0
FINAL_SEED_VERSION = 39 # electrum >= 2.7 will set this to prevent FINAL_SEED_VERSION = 40 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format # old versions from overwriting new format
@ -188,6 +188,7 @@ class WalletDB(JsonDB):
self._convert_version_37() self._convert_version_37()
self._convert_version_38() self._convert_version_38()
self._convert_version_39() self._convert_version_39()
self._convert_version_40()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
self._after_upgrade_tasks() self._after_upgrade_tasks()
@ -787,6 +788,29 @@ class WalletDB(JsonDB):
self.data['imported_channel_backups'] = self.data.pop('channel_backups', {}) self.data['imported_channel_backups'] = self.data.pop('channel_backups', {})
self.data['seed_version'] = 39 self.data['seed_version'] = 39
def _convert_version_40(self):
# put 'seed_type' into keystores
if not self._is_upgrade_method_needed(39, 39):
return
for ks_name in ('keystore', *['x{}/'.format(i) for i in range(1, 16)]):
ks = self.data.get(ks_name, None)
if ks is None: continue
seed = ks.get('seed')
if not seed: continue
seed_type = None
xpub = ks.get('xpub') or None
if xpub:
assert isinstance(xpub, str)
if xpub[0:4] in ('xpub', 'tpub'):
seed_type = 'standard'
elif xpub[0:4] in ('zpub', 'Zpub', 'vpub', 'Vpub'):
seed_type = 'segwit'
elif ks.get('type') == 'old':
seed_type = 'old'
if seed_type is not None:
ks['seed_type'] = seed_type
self.data['seed_version'] = 40
def _convert_imported(self): def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13): if not self._is_upgrade_method_needed(0, 13):
return return

Loading…
Cancel
Save