Remove constructor method of plugins
Clean up wallet class loading.
This commit is contained in:
parent
cf4ee487cd
commit
1d07960290
|
@ -118,10 +118,13 @@ class Plugins(DaemonThread):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def register_plugin_wallet(self, name, gui_good, details):
|
def register_plugin_wallet(self, name, gui_good, details):
|
||||||
|
def dynamic_constructor(storage):
|
||||||
|
return self.wallet_plugin_loader(name).wallet_class(storage)
|
||||||
|
|
||||||
if details[0] == 'hardware':
|
if details[0] == 'hardware':
|
||||||
self.hw_wallets[name] = (gui_good, details)
|
self.hw_wallets[name] = (gui_good, details)
|
||||||
register = details + (lambda: self.wallet_plugin_loader(name),)
|
self.print_error("registering wallet %s: %s" %(name, details))
|
||||||
wallet.wallet_types.append(register)
|
wallet.wallet_types.append(details + (dynamic_constructor,))
|
||||||
|
|
||||||
def wallet_plugin_loader(self, name):
|
def wallet_plugin_loader(self, name):
|
||||||
if not name in self.plugins:
|
if not name in self.plugins:
|
||||||
|
|
|
@ -1908,25 +1908,7 @@ class Wallet(object):
|
||||||
raise BaseException(msg)
|
raise BaseException(msg)
|
||||||
|
|
||||||
wallet_type = storage.get('wallet_type')
|
wallet_type = storage.get('wallet_type')
|
||||||
if wallet_type:
|
WalletClass = Wallet.wallet_class(wallet_type, seed_version)
|
||||||
for cat, t, name, loader in wallet_types:
|
|
||||||
if t == wallet_type:
|
|
||||||
if cat in ['hardware', 'twofactor']:
|
|
||||||
WalletClass = lambda storage: apply(loader().constructor, (storage,))
|
|
||||||
else:
|
|
||||||
WalletClass = loader
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
if re.match('(\d+)of(\d+)', wallet_type):
|
|
||||||
WalletClass = Multisig_Wallet
|
|
||||||
else:
|
|
||||||
raise RuntimeError("Unknown wallet type: " + wallet_type)
|
|
||||||
else:
|
|
||||||
if seed_version == OLD_SEED_VERSION:
|
|
||||||
WalletClass = OldWallet
|
|
||||||
else:
|
|
||||||
WalletClass = NewWallet
|
|
||||||
|
|
||||||
wallet = WalletClass(storage)
|
wallet = WalletClass(storage)
|
||||||
|
|
||||||
# Convert hardware wallets restored with older versions of
|
# Convert hardware wallets restored with older versions of
|
||||||
|
@ -1940,6 +1922,20 @@ class Wallet(object):
|
||||||
|
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def wallet_class(wallet_type, seed_version):
|
||||||
|
if wallet_type:
|
||||||
|
if Wallet.multisig_type(wallet_type):
|
||||||
|
return Multisig_Wallet
|
||||||
|
|
||||||
|
for info in wallet_types:
|
||||||
|
if wallet_type == info[1]:
|
||||||
|
return info[3]
|
||||||
|
|
||||||
|
raise RuntimeError("Unknown wallet type: " + wallet_type)
|
||||||
|
|
||||||
|
return OldWallet if seed_version == OLD_SEED_VERSION else NewWallet
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_seed(seed):
|
def is_seed(seed):
|
||||||
return is_old_seed(seed) or is_new_seed(seed)
|
return is_old_seed(seed) or is_new_seed(seed)
|
||||||
|
|
|
@ -419,9 +419,6 @@ class LedgerPlugin(BasePlugin):
|
||||||
self.device = self.wallet_class.device
|
self.device = self.wallet_class.device
|
||||||
self.handler = None
|
self.handler = None
|
||||||
|
|
||||||
def constructor(self, s):
|
|
||||||
return BTChipWallet(s)
|
|
||||||
|
|
||||||
def is_enabled(self):
|
def is_enabled(self):
|
||||||
return BTCHIP
|
return BTCHIP
|
||||||
|
|
||||||
|
|
|
@ -129,9 +129,6 @@ class TrezorCompatiblePlugin(BasePlugin):
|
||||||
self.client = None
|
self.client = None
|
||||||
self.wallet_class.plugin = self
|
self.wallet_class.plugin = self
|
||||||
|
|
||||||
def constructor(self, s):
|
|
||||||
return self.wallet_class(s)
|
|
||||||
|
|
||||||
def give_error(self, message):
|
def give_error(self, message):
|
||||||
self.print_error(message)
|
self.print_error(message)
|
||||||
raise Exception(message)
|
raise Exception(message)
|
||||||
|
|
|
@ -31,7 +31,7 @@ from electrum.i18n import _
|
||||||
from electrum.plugins import hook
|
from electrum.plugins import hook
|
||||||
from electrum import wizard
|
from electrum import wizard
|
||||||
|
|
||||||
from trustedcoin import TrustedCoinPlugin, Wallet_2fa, DISCLAIMER, server
|
from trustedcoin import TrustedCoinPlugin, DISCLAIMER, server
|
||||||
|
|
||||||
def need_server(wallet, tx):
|
def need_server(wallet, tx):
|
||||||
from electrum.account import BIP32_Account
|
from electrum.account import BIP32_Account
|
||||||
|
@ -79,7 +79,8 @@ class Plugin(TrustedCoinPlugin):
|
||||||
def sign_tx(self, window, tx):
|
def sign_tx(self, window, tx):
|
||||||
self.print_error("twofactor:sign_tx")
|
self.print_error("twofactor:sign_tx")
|
||||||
wallet = window.wallet
|
wallet = window.wallet
|
||||||
if type(wallet) is Wallet_2fa and not wallet.can_sign_without_server():
|
assert isinstace(wallet, self.wallet_class)
|
||||||
|
if not wallet.can_sign_without_server():
|
||||||
auth_code = None
|
auth_code = None
|
||||||
if need_server(wallet, tx):
|
if need_server(wallet, tx):
|
||||||
auth_code = self.auth_dialog(window)
|
auth_code = self.auth_dialog(window)
|
||||||
|
@ -100,7 +101,8 @@ class Plugin(TrustedCoinPlugin):
|
||||||
@hook
|
@hook
|
||||||
def abort_send(self, window):
|
def abort_send(self, window):
|
||||||
wallet = window.wallet
|
wallet = window.wallet
|
||||||
if type(wallet) is Wallet_2fa and not wallet.can_sign_without_server():
|
assert isinstace(wallet, self.wallet_class)
|
||||||
|
if not wallet.can_sign_without_server():
|
||||||
if wallet.billing_info is None:
|
if wallet.billing_info is None:
|
||||||
# request billing info before forming the transaction
|
# request billing info before forming the transaction
|
||||||
waiting_dialog(self, window).wait()
|
waiting_dialog(self, window).wait()
|
||||||
|
|
|
@ -287,13 +287,11 @@ def make_billing_address(wallet, num):
|
||||||
|
|
||||||
|
|
||||||
class TrustedCoinPlugin(BasePlugin):
|
class TrustedCoinPlugin(BasePlugin):
|
||||||
|
wallet_class = Wallet_2fa
|
||||||
|
|
||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config, name):
|
||||||
BasePlugin.__init__(self, parent, config, name)
|
BasePlugin.__init__(self, parent, config, name)
|
||||||
Wallet_2fa.plugin = self
|
self.wallet_class.plugin = self
|
||||||
|
|
||||||
def constructor(self, s):
|
|
||||||
return Wallet_2fa(s)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_seed(seed):
|
def is_valid_seed(seed):
|
||||||
|
@ -348,7 +346,7 @@ class TrustedCoinPlugin(BasePlugin):
|
||||||
window.wallet.is_billing = False
|
window.wallet.is_billing = False
|
||||||
|
|
||||||
def on_restore_wallet(self, wallet, wizard):
|
def on_restore_wallet(self, wallet, wizard):
|
||||||
assert isinstance(wallet, Wallet_2fa)
|
assert isinstance(wallet, self.wallet_class)
|
||||||
|
|
||||||
seed = wizard.request_seed(RESTORE_MSG, is_valid=self.is_valid_seed)
|
seed = wizard.request_seed(RESTORE_MSG, is_valid=self.is_valid_seed)
|
||||||
password = wizard.request_password()
|
password = wizard.request_password()
|
||||||
|
|
Loading…
Reference in New Issue