mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Format upgrade: increment seed_version to make sure that old versions of Electrum refuse to open new wallet files.
This commit is contained in:
parent
a815d5b3c3
commit
16ed48d52d
3 changed files with 23 additions and 21 deletions
|
@ -37,7 +37,7 @@ from i18n import _
|
||||||
from util import NotEnoughFunds, PrintError, profiler
|
from util import NotEnoughFunds, PrintError, profiler
|
||||||
from plugins import run_hook, plugin_loaders
|
from plugins import run_hook, plugin_loaders
|
||||||
from keystore import bip44_derivation
|
from keystore import bip44_derivation
|
||||||
from version import OLD_SEED_VERSION
|
from version import *
|
||||||
|
|
||||||
|
|
||||||
def multisig_type(wallet_type):
|
def multisig_type(wallet_type):
|
||||||
|
@ -127,6 +127,8 @@ class WalletStorage(PrintError):
|
||||||
self.data.pop(key)
|
self.data.pop(key)
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
|
# this ensures that previous versions of electrum won't open the wallet
|
||||||
|
self.put('seed_version', FINAL_SEED_VERSION)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._write()
|
self._write()
|
||||||
self.file_exists = True
|
self.file_exists = True
|
||||||
|
@ -206,23 +208,18 @@ class WalletStorage(PrintError):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def requires_upgrade(self):
|
def requires_upgrade(self):
|
||||||
r = False
|
return self.file_exists and self.get_seed_version() != FINAL_SEED_VERSION
|
||||||
if self.file_exists:
|
|
||||||
r |= self.convert_wallet_type(True)
|
|
||||||
r |= self.convert_imported(True)
|
|
||||||
return r
|
|
||||||
|
|
||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
self.convert_imported(False)
|
self.convert_imported()
|
||||||
self.convert_wallet_type(False)
|
self.convert_wallet_type()
|
||||||
|
self.convert_account()
|
||||||
self.write()
|
self.write()
|
||||||
|
|
||||||
def convert_wallet_type(self, is_test):
|
def convert_wallet_type(self):
|
||||||
wallet_type = self.get('wallet_type')
|
wallet_type = self.get('wallet_type')
|
||||||
if self.get('keystore') or self.get('x1/') or wallet_type=='imported':
|
if self.get('keystore') or self.get('x1/') or wallet_type=='imported':
|
||||||
return False
|
return False
|
||||||
if is_test:
|
|
||||||
return True
|
|
||||||
assert not self.requires_split()
|
assert not self.requires_split()
|
||||||
seed_version = self.get_seed_version()
|
seed_version = self.get_seed_version()
|
||||||
seed = self.get('seed')
|
seed = self.get('seed')
|
||||||
|
@ -293,14 +290,11 @@ class WalletStorage(PrintError):
|
||||||
self.put('keypairs', None)
|
self.put('keypairs', None)
|
||||||
self.put('key_type', None)
|
self.put('key_type', None)
|
||||||
|
|
||||||
|
def convert_imported(self):
|
||||||
def convert_imported(self, test):
|
|
||||||
# '/x' is the internal ID for imported accounts
|
# '/x' is the internal ID for imported accounts
|
||||||
d = self.get('accounts', {}).get('/x', {}).get('imported',{})
|
d = self.get('accounts', {}).get('/x', {}).get('imported',{})
|
||||||
if not d:
|
if not d:
|
||||||
return False
|
return False
|
||||||
if test:
|
|
||||||
return True
|
|
||||||
addresses = []
|
addresses = []
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
for addr, v in d.items():
|
for addr, v in d.items():
|
||||||
|
@ -322,6 +316,13 @@ class WalletStorage(PrintError):
|
||||||
else:
|
else:
|
||||||
raise BaseException('no addresses or privkeys')
|
raise BaseException('no addresses or privkeys')
|
||||||
|
|
||||||
|
def convert_account(self):
|
||||||
|
d = self.get('accounts', {}).get('0', {})
|
||||||
|
if not d:
|
||||||
|
return False
|
||||||
|
self.put('accounts', None)
|
||||||
|
self.put('pubkeys', d)
|
||||||
|
|
||||||
def get_action(self):
|
def get_action(self):
|
||||||
action = run_hook('get_action', self)
|
action = run_hook('get_action', self)
|
||||||
if action:
|
if action:
|
||||||
|
@ -330,11 +331,10 @@ class WalletStorage(PrintError):
|
||||||
return 'new'
|
return 'new'
|
||||||
|
|
||||||
def get_seed_version(self):
|
def get_seed_version(self):
|
||||||
from version import OLD_SEED_VERSION, NEW_SEED_VERSION
|
|
||||||
seed_version = self.get('seed_version')
|
seed_version = self.get('seed_version')
|
||||||
if not seed_version:
|
if not seed_version:
|
||||||
seed_version = OLD_SEED_VERSION if len(self.get('master_public_key','')) == 128 else NEW_SEED_VERSION
|
seed_version = OLD_SEED_VERSION if len(self.get('master_public_key','')) == 128 else NEW_SEED_VERSION
|
||||||
if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION]:
|
if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION, FINAL_SEED_VERSION]:
|
||||||
msg = "Your wallet has an unsupported seed version."
|
msg = "Your wallet has an unsupported seed version."
|
||||||
msg += '\n\nWallet file: %s' % os.path.abspath(self.path)
|
msg += '\n\nWallet file: %s' % os.path.abspath(self.path)
|
||||||
if seed_version in [5, 7, 8, 9, 10]:
|
if seed_version in [5, 7, 8, 9, 10]:
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
ELECTRUM_VERSION = '2.7.0' # version of the client package
|
ELECTRUM_VERSION = '2.7.0' # version of the client package
|
||||||
PROTOCOL_VERSION = '0.10' # protocol version requested
|
PROTOCOL_VERSION = '0.10' # protocol version requested
|
||||||
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
|
||||||
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
||||||
|
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
||||||
|
FINAL_SEED_VERSION = 12 # electrum >= 2.7 will set this to prevent
|
||||||
|
# old versions from overwriting new format
|
||||||
|
|
||||||
|
|
||||||
# The hash of the mnemonic seed must begin with this
|
# The hash of the mnemonic seed must begin with this
|
||||||
|
|
|
@ -209,11 +209,10 @@ class Abstract_Wallet(PrintError):
|
||||||
return os.path.basename(self.storage.path)
|
return os.path.basename(self.storage.path)
|
||||||
|
|
||||||
def save_pubkeys(self):
|
def save_pubkeys(self):
|
||||||
# this name is inherited from old multi-account wallets
|
self.storage.put('pubkeys', {'receiving':self.receiving_pubkeys, 'change':self.change_pubkeys})
|
||||||
self.storage.put('accounts', {'0': {'receiving':self.receiving_pubkeys, 'change':self.change_pubkeys}})
|
|
||||||
|
|
||||||
def load_addresses(self):
|
def load_addresses(self):
|
||||||
d = self.storage.get('accounts', {}).get('0', {})
|
d = self.storage.get('pubkeys', {})
|
||||||
self.receiving_pubkeys = d.get('receiving', [])
|
self.receiving_pubkeys = d.get('receiving', [])
|
||||||
self.change_pubkeys = d.get('change', [])
|
self.change_pubkeys = d.get('change', [])
|
||||||
self.receiving_addresses = map(self.pubkeys_to_address, self.receiving_pubkeys)
|
self.receiving_addresses = map(self.pubkeys_to_address, self.receiving_pubkeys)
|
||||||
|
|
Loading…
Add table
Reference in a new issue