electrum

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

commit 79588eb4dacb40607bd014082b0bea781687ba64
parent 337a20b815ac64c8335c84ad9cf7eac3ac62eeac
Author: ThomasV <thomasv@gitorious>
Date:   Sun, 31 Aug 2014 15:33:20 +0200

init plugins before gui. register wallet types in plugin constructor

Diffstat:
Melectrum | 4++++
Mgui/qt/__init__.py | 4+---
Mgui/qt/installwizard.py | 9++-------
Mlib/plugins.py | 9++++-----
Mlib/wallet.py | 32+++++++++++++++++++-------------
Mplugins/btchipwallet.py | 17+++++++++++------
Mplugins/coinbase_buyback.py | 4++++
Mplugins/cosigner_pool.py | 4++--
Mplugins/exchange_rate.py | 3++-
Mplugins/labels.py | 6+++---
Mplugins/trezor.py | 16++++++++--------
Mplugins/virtualkeyboard.py | 4+++-
12 files changed, 63 insertions(+), 49 deletions(-)

diff --git a/electrum b/electrum @@ -47,6 +47,9 @@ from electrum import util from electrum import SimpleConfig, Network, Wallet, WalletStorage, NetworkProxy, Commands, known_commands, pick_random_server from electrum.util import print_msg, print_stderr, print_json, set_verbosity from electrum.daemon import get_daemon +from electrum.plugins import init_plugins + + # get password routine def prompt_password(prompt, confirm=True): @@ -173,6 +176,7 @@ if __name__ == '__main__': set_verbosity(config_options.get('verbose')) config = SimpleConfig(config_options) + init_plugins(config) if len(args) == 0: url = None diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -44,7 +44,6 @@ except Exception: from util import * from main_window import ElectrumWindow -from electrum.plugins import init_plugins class OpenFileEventFilter(QObject): @@ -70,7 +69,6 @@ class ElectrumGui: if app is None: self.app = QApplication(sys.argv) self.app.installEventFilter(self.efilter) - init_plugins(self) def build_tray_menu(self): @@ -193,7 +191,7 @@ class ElectrumGui: self.go_full() # plugins that need to change the GUI do it here - run_hook('init') + run_hook('init_qt', self) w.load_wallet(wallet) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -2,6 +2,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * import PyQt4.QtCore as QtCore +import electrum from electrum.i18n import _ from electrum import Wallet, Wallet_2of2, Wallet_2of3 from electrum import bitcoin @@ -96,13 +97,7 @@ class InstallWizard(QDialog): grid.addWidget(gb2, 3, 0) group2 = QButtonGroup() - self.wallet_types = [ - ('standard', _("Standard wallet"), Wallet), - ('2of2', _("Multisig wallet (2 of 2)"), Wallet_2of2), - ('2of3', _("Multisig wallet (2 of 3)"), Wallet_2of3) - ] - run_hook('add_wallet_types', self.wallet_types) - + self.wallet_types = filter(lambda x: x[0] not in ['old','xpub','imported'], electrum.wallet.wallet_types) for i, (t,l,c) in enumerate(self.wallet_types): button = QRadioButton(gb2) button.setText(l) diff --git a/lib/plugins.py b/lib/plugins.py @@ -6,7 +6,7 @@ from i18n import _ plugins = [] -def init_plugins(self): +def init_plugins(config): import imp, pkgutil, __builtin__, os global plugins @@ -23,7 +23,7 @@ def init_plugins(self): for name, p in zip(plugin_names, plugin_modules): try: - plugins.append( p.Plugin(self, name) ) + plugins.append( p.Plugin(config, name) ) except Exception: print_msg(_("Error: cannot initialize plugin"),p) traceback.print_exc(file=sys.stdout) @@ -61,10 +61,9 @@ def run_hook(name, *args): class BasePlugin: - def __init__(self, gui, name): - self.gui = gui + def __init__(self, config, name): self.name = name - self.config = gui.config + self.config = config # add self to hooks for k in dir(self): if k in hook_names: diff --git a/lib/wallet.py b/lib/wallet.py @@ -1559,6 +1559,17 @@ class OldWallet(Deterministic_Wallet): return True return False + + +wallet_types = [ + ('old', ("Old wallet"), OldWallet), + ('xpub', ("BIP32 Import"), BIP32_Simple_Wallet), + ('standard', ("Standard wallet"), NewWallet), + ('imported', ("Imported wallet"), Imported_Wallet), + ('2of2', ("Multisig wallet (2 of 2)"), Wallet_2of2), + ('2of3', ("Multisig wallet (2 of 3)"), Wallet_2of3) +] + # former WalletFactory class Wallet(object): """The main wallet "entry point". @@ -1568,19 +1579,14 @@ class Wallet(object): def __new__(self, storage): config = storage.config - self.wallet_types = [ - ('old', ("Old wallet"), OldWallet), - ('xpub', ("BIP32 Import"), BIP32_Simple_Wallet), - ('standard', ("Standard wallet"), NewWallet), - ('imported', ("Imported wallet"), Imported_Wallet), - ('2of2', ("Multisig wallet (2 of 2)"), Wallet_2of2), - ('2of3', ("Multisig wallet (2 of 3)"), Wallet_2of3) - ] - run_hook('add_wallet_types', self.wallet_types) - - for t, l, WalletClass in self.wallet_types: - if t == storage.get('wallet_type'): - return WalletClass(storage) + run_hook('add_wallet_types', wallet_types) + wallet_type = storage.get('wallet_type') + if wallet_type: + for t, l, WalletClass in wallet_types: + if t == wallet_type: + return WalletClass(storage) + else: + raise BaseException('unknown wallet type', wallet_type) if not storage.file_exists: seed_version = NEW_SEED_VERSION diff --git a/plugins/btchipwallet.py b/plugins/btchipwallet.py @@ -7,6 +7,7 @@ from sys import stderr from time import sleep from base64 import b64encode, b64decode +import electrum from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum_gui.qt.util import ok_cancel_buttons from electrum.account import BIP32_Account @@ -41,14 +42,18 @@ def give_error(message): class Plugin(BasePlugin): - def fullname(self): return 'BTChip Wallet' + def fullname(self): + return 'BTChip Wallet' - def description(self): return 'Provides support for BTChip hardware wallet\n\nRequires github.com/btchip/btchip-python' + def description(self): + return 'Provides support for BTChip hardware wallet\n\nRequires github.com/btchip/btchip-python' def __init__(self, gui, name): BasePlugin.__init__(self, gui, name) self._is_available = self._init() self.wallet = None + electrum.wallet.wallet_types.append(('btchip', _("BTChip wallet"), BTChipWallet)) + def _init(self): return BTCHIP @@ -76,12 +81,12 @@ class Plugin(BasePlugin): return BasePlugin.enable(self) @hook - def load_wallet(self, wallet): - self.wallet = wallet + def init_qt(self, gui): + self.gui = gui @hook - def add_wallet_types(self, wallet_types): - wallet_types.append(('btchip', _("BTChip wallet"), BTChipWallet)) + def load_wallet(self, wallet): + self.wallet = wallet @hook def installwizard_restore(self, wizard, storage): diff --git a/plugins/coinbase_buyback.py b/plugins/coinbase_buyback.py @@ -52,6 +52,10 @@ class Plugin(BasePlugin): def _init(self): return loaded_qweb + @hook + def init_qt(self, gui): + self.gui = gui + def is_available(self): return self._is_available diff --git a/plugins/cosigner_pool.py b/plugins/cosigner_pool.py @@ -90,8 +90,8 @@ class Plugin(BasePlugin): return description @hook - def init(self): - self.win = self.gui.main_window + def init_qt(self, gui): + self.win = gui.main_window self.win.connect(self.win, SIGNAL('cosigner:receive'), self.on_receive) if self.listener is None: self.listener = Listener(self) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py @@ -339,7 +339,8 @@ class Plugin(BasePlugin): self.exchanges = [self.config.get('use_exchange', "Blockchain")] @hook - def init(self): + def init_qt(self, gui): + self.gui = gui self.win = self.gui.main_window self.win.connect(self.win, SIGNAL("refresh_currencies()"), self.win.update_status) self.btc_rate = Decimal("0.0") diff --git a/plugins/labels.py b/plugins/labels.py @@ -44,9 +44,9 @@ class Plugin(BasePlugin): return decoded_message @hook - def init(self): + def init_qt(self, gui): self.target_host = 'labelectrum.herokuapp.com' - self.window = self.gui.main_window + self.window = gui.main_window @hook def load_wallet(self, wallet): @@ -154,7 +154,7 @@ class Plugin(BasePlugin): def enable(self): if not self.auth_token(): # First run, throw plugin settings in your face self.init() - self.load_wallet(self.gui.main_window.wallet) + self.load_wallet(self.window.wallet) if self.settings_dialog(): self.set_enabled(True) return True diff --git a/plugins/trezor.py b/plugins/trezor.py @@ -6,6 +6,7 @@ from sys import stderr from time import sleep from base64 import b64encode, b64decode +import electrum from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum_gui.qt.util import ok_cancel_buttons, EnterButton from electrum.account import BIP32_Account @@ -36,15 +37,18 @@ def give_error(message): class Plugin(BasePlugin): - def fullname(self): return 'Trezor Wallet' + def fullname(self): + return 'Trezor Wallet' - def description(self): return 'Provides support for Trezor hardware wallet\n\nRequires github.com/trezor/python-trezor' + def description(self): + return 'Provides support for Trezor hardware wallet\n\nRequires github.com/trezor/python-trezor' - def __init__(self, gui, name): - BasePlugin.__init__(self, gui, name) + def __init__(self, config, name): + BasePlugin.__init__(self, config, name) self._is_available = self._init() self._requires_settings = True self.wallet = None + electrum.wallet.wallet_types.append(('trezor', _("Trezor wallet"), TrezorWallet)) def _init(self): return TREZOR @@ -79,10 +83,6 @@ class Plugin(BasePlugin): self.wallet = wallet @hook - def add_wallet_types(self, wallet_types): - wallet_types.append(('trezor', _("Trezor wallet"), TrezorWallet)) - - @hook def installwizard_restore(self, wizard, storage): if storage.get('wallet_type') != 'trezor': return diff --git a/plugins/virtualkeyboard.py b/plugins/virtualkeyboard.py @@ -11,7 +11,9 @@ class Plugin(BasePlugin): def description(self): return '%s\n%s' % (_("Add an optional virtual keyboard to the password dialog."), _("Warning: do not use this if it makes you pick a weaker password.")) - def init(self): + @hook + def init_qt(self, gui): + self.gui = gui self.vkb = None self.vkb_index = 0