electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 778297697ab5fa6a0dda11165d9a7f6ca597ed34
parent 71046371ecb293a016f5777c3070fbdc933638ff
Author: ThomasV <thomasv@gitorious>
Date:   Sun, 24 May 2015 20:37:05 +0200

lazy plugin constructor

Diffstat:
Mgui/qt/main_window.py | 1+
Mlib/plugins.py | 25+++++++++++++++----------
Mplugins/__init__.py | 6+++---
Mplugins/btchipwallet.py | 4++--
Mplugins/trezor.py | 4++--
Mplugins/trustedcoin.py | 4++--
6 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -235,6 +235,7 @@ class ElectrumWindow(QMainWindow): self.clear_receive_tab() self.update_receive_tab() self.show() + run_hook('init_qt', self.gui_object) run_hook('load_wallet', wallet) def import_old_contacts(self): diff --git a/lib/plugins.py b/lib/plugins.py @@ -60,15 +60,18 @@ def init_plugins(config, is_local, gui_name): electrum_plugins = __import__('electrum_plugins') loader = lambda name: __import__('electrum_plugins.' + name, fromlist=['electrum_plugins']) - def register_wallet_type(name): - # fixme: load plugins only if really needed + def constructor(name, storage): + if plugins.get(name) is None: + try: + p = loader(name) + plugins[name] = p.Plugin(config, name) + except: + return + return plugins[name].constructor(storage) + + def register_wallet_type(name, x, constructor): import wallet - try: - p = loader(name) - plugins[name] = p.Plugin(config, name) - except: - return - x = plugins[name].get_wallet_type() + x += (lambda storage: constructor(name, storage),) wallet.wallet_types.append(x) descriptions = electrum_plugins.descriptions @@ -76,8 +79,9 @@ def init_plugins(config, is_local, gui_name): name = item['name'] if gui_name not in item.get('available_for', []): continue - if item.get('registers_wallet_type'): - register_wallet_type(name) + x = item.get('registers_wallet_type') + if x: + register_wallet_type(name, x, constructor) if not config.get('use_' + name): continue try: @@ -87,6 +91,7 @@ def init_plugins(config, is_local, gui_name): print_msg(_("Error: cannot initialize plugin"), name) traceback.print_exc(file=sys.stdout) + hook_names = set() hooks = {} diff --git a/plugins/__init__.py b/plugins/__init__.py @@ -32,7 +32,7 @@ descriptions = [ 'description': _('Provides support for BTChip hardware wallet'), 'requires': [('btchip', 'github.com/btchip/btchip-python')], 'requires_wallet_type': ['btchip'], - 'registers_wallet_type': True, + 'registers_wallet_type': ('hardware', 'btchip', _("BTChip wallet")), 'available_for': ['qt'], }, { @@ -88,7 +88,7 @@ descriptions = [ 'available_for': ['qt'], 'requires': [('trezorlib','github.com/trezor/python-trezor')], 'requires_wallet_type': ['trezor'], - 'registers_wallet_type': True, + 'registers_wallet_type': ('hardware', 'trezor', _("Trezor wallet")), 'available_for': ['qt', 'cmdline'], }, { @@ -100,7 +100,7 @@ descriptions = [ " <a href=\"https://api.trustedcoin.com/#/electrum-help\">https://api.trustedcoin.com/#/electrum-help</a>" ]), 'requires_wallet_type': ['2fa'], - 'registers_wallet_type': True, + 'registers_wallet_type': ('twofactor', '2fa', _("Wallet with two-factor authentication")), 'available_for': ['qt', 'cmdline'], }, { diff --git a/plugins/btchipwallet.py b/plugins/btchipwallet.py @@ -40,8 +40,8 @@ class Plugin(BasePlugin): self._is_available = self._init() self.wallet = None - def get_wallet_type(self): - return ('hardware', 'btchip', _("BTChip wallet"), BTChipWallet) + def constructor(self, s): + return BTChipWallet(s) def _init(self): return BTCHIP diff --git a/plugins/trezor.py b/plugins/trezor.py @@ -47,8 +47,8 @@ class Plugin(BasePlugin): self._requires_settings = True self.wallet = None - def get_wallet_type(self): - return ('hardware', 'trezor', _("Trezor wallet"), TrezorWallet) + def constructor(self, s): + return TrezorWallet(s) def _init(self): return TREZOR diff --git a/plugins/trustedcoin.py b/plugins/trustedcoin.py @@ -214,8 +214,8 @@ class Plugin(BasePlugin): self.billing_info = None self.is_billing = False - def get_wallet_type(self): - return ('twofactor', '2fa', _("Wallet with two-factor authentication"), Wallet_2fa) + def constructor(self, s): + return Wallet_2fa(s) def is_available(self): if not self.wallet: