|
@ -62,8 +62,9 @@ def multisig_type(wallet_type): |
|
|
|
|
|
|
|
|
class WalletStorage(PrintError): |
|
|
class WalletStorage(PrintError): |
|
|
|
|
|
|
|
|
def __init__(self, path): |
|
|
def __init__(self, path, manual_upgrades=False): |
|
|
self.print_error("wallet path", path) |
|
|
self.print_error("wallet path", path) |
|
|
|
|
|
self.manual_upgrades = manual_upgrades |
|
|
self.lock = threading.RLock() |
|
|
self.lock = threading.RLock() |
|
|
self.data = {} |
|
|
self.data = {} |
|
|
self.path = path |
|
|
self.path = path |
|
@ -74,6 +75,9 @@ class WalletStorage(PrintError): |
|
|
self.raw = f.read() |
|
|
self.raw = f.read() |
|
|
if not self.is_encrypted(): |
|
|
if not self.is_encrypted(): |
|
|
self.load_data(self.raw) |
|
|
self.load_data(self.raw) |
|
|
|
|
|
else: |
|
|
|
|
|
# avoid new wallets getting 'upgraded' |
|
|
|
|
|
self.put('seed_version', FINAL_SEED_VERSION) |
|
|
|
|
|
|
|
|
def load_data(self, s): |
|
|
def load_data(self, s): |
|
|
try: |
|
|
try: |
|
@ -99,6 +103,12 @@ class WalletStorage(PrintError): |
|
|
l = plugin_loaders.get(t) |
|
|
l = plugin_loaders.get(t) |
|
|
if l: l() |
|
|
if l: l() |
|
|
|
|
|
|
|
|
|
|
|
if not self.manual_upgrades: |
|
|
|
|
|
if self.requires_split(): |
|
|
|
|
|
raise BaseException("This wallet has multiple accounts and must be split") |
|
|
|
|
|
if self.requires_upgrade(): |
|
|
|
|
|
self.upgrade() |
|
|
|
|
|
|
|
|
def is_encrypted(self): |
|
|
def is_encrypted(self): |
|
|
try: |
|
|
try: |
|
|
return base64.b64decode(self.raw)[0:4] == b'BIE1' |
|
|
return base64.b64decode(self.raw)[0:4] == b'BIE1' |
|
@ -155,8 +165,6 @@ class WalletStorage(PrintError): |
|
|
|
|
|
|
|
|
@profiler |
|
|
@profiler |
|
|
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() |
|
|
|
|
|
|
|
@ -244,10 +252,14 @@ class WalletStorage(PrintError): |
|
|
return self.file_exists() and self.get_seed_version() != FINAL_SEED_VERSION |
|
|
return self.file_exists() and self.get_seed_version() != FINAL_SEED_VERSION |
|
|
|
|
|
|
|
|
def upgrade(self): |
|
|
def upgrade(self): |
|
|
|
|
|
self.print_error('upgrading wallet format') |
|
|
|
|
|
|
|
|
self.convert_imported() |
|
|
self.convert_imported() |
|
|
self.convert_wallet_type() |
|
|
self.convert_wallet_type() |
|
|
self.convert_account() |
|
|
self.convert_account() |
|
|
self.convert_version_14() |
|
|
self.convert_version_14() |
|
|
|
|
|
|
|
|
|
|
|
self.put('seed_version', FINAL_SEED_VERSION) |
|
|
self.write() |
|
|
self.write() |
|
|
|
|
|
|
|
|
def convert_wallet_type(self): |
|
|
def convert_wallet_type(self): |
|
@ -338,6 +350,8 @@ class WalletStorage(PrintError): |
|
|
|
|
|
|
|
|
def convert_version_14(self): |
|
|
def convert_version_14(self): |
|
|
# convert imported wallets for 3.0 |
|
|
# convert imported wallets for 3.0 |
|
|
|
|
|
if self.get_seed_version() >= 14: |
|
|
|
|
|
return |
|
|
if self.get('wallet_type') =='imported': |
|
|
if self.get('wallet_type') =='imported': |
|
|
addresses = self.get('addresses') |
|
|
addresses = self.get('addresses') |
|
|
if type(addresses) is list: |
|
|
if type(addresses) is list: |
|
|