SomberNight 6 years ago
parent
commit
99b83f7527
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 27
      electrum/base_wizard.py
  2. 12
      electrum/plugins/trustedcoin/trustedcoin.py

27
electrum/base_wizard.py

@ -67,6 +67,13 @@ class WizardStackItem(NamedTuple):
storage_data: dict storage_data: dict
class WizardWalletPasswordSetting(NamedTuple):
password: Optional[str]
encrypt_storage: bool
storage_enc_version: StorageEncryptionVersion
encrypt_keystore: bool
class BaseWizard(Logger): class BaseWizard(Logger):
def __init__(self, config: SimpleConfig, plugins: Plugins): def __init__(self, config: SimpleConfig, plugins: Plugins):
@ -75,7 +82,7 @@ class BaseWizard(Logger):
self.config = config self.config = config
self.plugins = plugins self.plugins = plugins
self.data = {} self.data = {}
self.pw_args = None self.pw_args = None # type: Optional[WizardWalletPasswordSetting]
self._stack = [] # type: List[WizardStackItem] self._stack = [] # type: List[WizardStackItem]
self.plugin = None self.plugin = None
self.keystores = [] self.keystores = []
@ -555,8 +562,9 @@ class BaseWizard(Logger):
encrypt_keystore=encrypt_keystore), encrypt_keystore=encrypt_keystore),
force_disable_encrypt_cb=not encrypt_keystore) force_disable_encrypt_cb=not encrypt_keystore)
def on_password(self, password, *, encrypt_storage, def on_password(self, password, *, encrypt_storage: bool,
storage_enc_version=StorageEncryptionVersion.USER_PASSWORD, encrypt_keystore): storage_enc_version=StorageEncryptionVersion.USER_PASSWORD,
encrypt_keystore: bool):
for k in self.keystores: for k in self.keystores:
if k.may_have_password(): if k.may_have_password():
k.update_password(None, password) k.update_password(None, password)
@ -573,7 +581,10 @@ class BaseWizard(Logger):
self.data['keystore'] = keys self.data['keystore'] = keys
else: else:
raise Exception('Unknown wallet type') raise Exception('Unknown wallet type')
self.pw_args = password, encrypt_storage, storage_enc_version self.pw_args = WizardWalletPasswordSetting(password=password,
encrypt_storage=encrypt_storage,
storage_enc_version=storage_enc_version,
encrypt_keystore=encrypt_keystore)
self.terminate() self.terminate()
def create_storage(self, path): def create_storage(self, path):
@ -581,12 +592,12 @@ class BaseWizard(Logger):
raise Exception('file already exists at path') raise Exception('file already exists at path')
if not self.pw_args: if not self.pw_args:
return return
password, encrypt_storage, storage_enc_version = self.pw_args pw_args = self.pw_args
self.pw_args = None # clean-up so that it can get GC-ed self.pw_args = None # clean-up so that it can get GC-ed
storage = WalletStorage(path) storage = WalletStorage(path)
storage.set_keystore_encryption(bool(password)) storage.set_keystore_encryption(bool(pw_args.password) and pw_args.encrypt_keystore)
if encrypt_storage: if pw_args.encrypt_storage:
storage.set_password(password, enc_version=storage_enc_version) storage.set_password(pw_args.password, enc_version=pw_args.storage_enc_version)
for key, value in self.data.items(): for key, value in self.data.items():
storage.put(key, value) storage.put(key, value)
storage.write() storage.write()

12
electrum/plugins/trustedcoin/trustedcoin.py

@ -47,7 +47,7 @@ from electrum.plugin import BasePlugin, hook
from electrum.util import NotEnoughFunds, UserFacingException from electrum.util import NotEnoughFunds, UserFacingException
from electrum.storage import StorageEncryptionVersion from electrum.storage import StorageEncryptionVersion
from electrum.network import Network from electrum.network import Network
from electrum.base_wizard import BaseWizard from electrum.base_wizard import BaseWizard, WizardWalletPasswordSetting
from electrum.logging import Logger from electrum.logging import Logger
@ -594,7 +594,10 @@ class TrustedCoinPlugin(BasePlugin):
k1.update_password(None, password) k1.update_password(None, password)
wizard.data['x1/'] = k1.dump() wizard.data['x1/'] = k1.dump()
wizard.data['x2/'] = k2.dump() wizard.data['x2/'] = k2.dump()
wizard.pw_args = password, encrypt_storage, StorageEncryptionVersion.USER_PASSWORD wizard.pw_args = WizardWalletPasswordSetting(password=password,
encrypt_storage=encrypt_storage,
storage_enc_version=StorageEncryptionVersion.USER_PASSWORD,
encrypt_keystore=bool(password))
self.go_online_dialog(wizard) self.go_online_dialog(wizard)
def restore_wallet(self, wizard): def restore_wallet(self, wizard):
@ -642,7 +645,10 @@ class TrustedCoinPlugin(BasePlugin):
xpub3 = make_xpub(get_signing_xpub(xtype), long_user_id) xpub3 = make_xpub(get_signing_xpub(xtype), long_user_id)
k3 = keystore.from_xpub(xpub3) k3 = keystore.from_xpub(xpub3)
wizard.data['x3/'] = k3.dump() wizard.data['x3/'] = k3.dump()
wizard.pw_args = password, encrypt_storage, StorageEncryptionVersion.USER_PASSWORD wizard.pw_args = WizardWalletPasswordSetting(password=password,
encrypt_storage=encrypt_storage,
storage_enc_version=StorageEncryptionVersion.USER_PASSWORD,
encrypt_keystore=bool(password))
wizard.terminate() wizard.terminate()
def create_remote_key(self, email, wizard): def create_remote_key(self, email, wizard):

Loading…
Cancel
Save