URI: 
       tsimplify wallet types - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 24a9ff3fef6a12d80c324c9329a7b568fab659c5
   DIR parent 058e49e839a0fefc5abcaec96d0b6747f915583d
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri, 19 Aug 2016 17:26:57 +0200
       
       simplify wallet types
       
       Diffstat:
         M lib/base_wizard.py                  |       9 ++++-----
         M lib/plugins.py                      |      12 ++++++------
         M lib/wallet.py                       |      37 +++++++++++++------------------
         M plugins/trustedcoin/__init__.py     |       2 +-
       
       4 files changed, 27 insertions(+), 33 deletions(-)
       ---
   DIR diff --git a/lib/base_wizard.py b/lib/base_wizard.py
       t@@ -25,7 +25,7 @@
        
        import os
        import keystore
       -from wallet import Wallet, Imported_Wallet, Standard_Wallet, Multisig_Wallet, WalletStorage
       +from wallet import Wallet, Imported_Wallet, Standard_Wallet, Multisig_Wallet, WalletStorage, wallet_types
        from i18n import _
        from plugins import run_hook
        
       t@@ -76,11 +76,10 @@ class BaseWizard(object):
                ])
                wallet_kinds = [
                    ('standard',  _("Standard wallet")),
       -            ('twofactor', _("Wallet with two-factor authentication")),
       +            ('2fa', _("Wallet with two-factor authentication")),
                    ('multisig',  _("Multi-signature wallet")),
                ]
       -        registered_kinds = Wallet.categories()
       -        choices = wallet_kinds#[pair for pair in wallet_kinds if pair[0] in registered_kinds]
       +        choices = [pair for pair in wallet_kinds if pair[0] in wallet_types]
                self.choice_dialog(title=title, message=message, choices=choices, run_next=self.on_wallet_type)
        
            def on_wallet_type(self, choice):
       t@@ -89,7 +88,7 @@ class BaseWizard(object):
                    action = 'choose_keystore'
                elif choice == 'multisig':
                    action = 'choose_multisig'
       -        elif choice == 'twofactor':
       +        elif choice == '2fa':
                    self.storage.put('wallet_type', '2fa')
                    self.storage.put('use_trustedcoin', True)
                    self.plugin = self.plugins.load_plugin('trustedcoin')
   DIR diff --git a/lib/plugins.py b/lib/plugins.py
       t@@ -153,14 +153,14 @@ class Plugins(DaemonThread):
                            self.print_error("cannot load plugin for:", name)
                return wallet_types, descs
        
       -    def register_wallet_type(self, name, gui_good, details):
       -        from wallet import Wallet
       -        global plugin_loaders
       +    def register_wallet_type(self, name, gui_good, wallet_type):
       +        from wallet import register_wallet_type, register_constructor
       +        self.print_error("registering wallet type", (wallet_type, name))
                def loader():
                    plugin = self.wallet_plugin_loader(name)
       -            Wallet.register_constructor(details[0], details[1], plugin.wallet_class)
       -        self.print_error("registering wallet type %s: %s" %(name, details))
       -        plugin_loaders[details[1]] = loader
       +            register_constructor(wallet_type, plugin.wallet_class)
       +        register_wallet_type(wallet_type)
       +        plugin_loaders[wallet_type] = loader
        
            def register_keystore(self, name, gui_good, details):
                from keystore import register_keystore
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -1530,7 +1530,20 @@ class Multisig_Wallet(Deterministic_Wallet):
        
        
        
       -WalletType = namedtuple("WalletType", "category type constructor")
       +wallet_types = ['standard', 'multisig', 'imported']
       +
       +def register_wallet_type(category):
       +    wallet_types.append(category)
       +
       +wallet_constructors = {
       +    'standard': Standard_Wallet,
       +    'old': Standard_Wallet,
       +    'xpub': Standard_Wallet,
       +    'imported': Imported_Wallet
       +}
       +
       +def register_constructor(wallet_type, constructor):
       +    wallet_constructors[wallet_type] = constructor
        
        
        # former WalletFactory
       t@@ -1539,15 +1552,6 @@ class Wallet(object):
            This class is actually a factory that will return a wallet of the correct
            type when passed a WalletStorage instance."""
        
       -    wallets = [   # category    type        constructor
       -        WalletType('standard', 'old',       Standard_Wallet),
       -        WalletType('standard', 'xpub',      Standard_Wallet),
       -        WalletType('standard', 'standard',  Standard_Wallet),
       -        WalletType('standard', 'imported',  Imported_Wallet),
       -        WalletType('multisig', '2of2',      Multisig_Wallet),
       -        WalletType('multisig', '2of3',      Multisig_Wallet),
       -    ]
       -
            def __new__(self, storage):
                wallet_type = storage.get('wallet_type')
                WalletClass = Wallet.wallet_class(wallet_type)
       t@@ -1563,20 +1567,11 @@ class Wallet(object):
                return wallet
        
            @staticmethod
       -    def categories():
       -        return [wallet.category for wallet in Wallet.wallets]
       -
       -    @staticmethod
       -    def register_constructor(category, type, constructor):
       -        Wallet.wallets.append(WalletType(category, type, constructor))
       -
       -    @staticmethod
            def wallet_class(wallet_type):
                if Wallet.multisig_type(wallet_type):
                    return Multisig_Wallet
       -        for wallet in Wallet.wallets:
       -            if wallet.type == wallet_type:
       -                return wallet.constructor
       +        if wallet_type in wallet_constructors:
       +            return wallet_constructors[wallet_type]
                raise RuntimeError("Unknown wallet type: " + wallet_type)
        
            @staticmethod
   DIR diff --git a/plugins/trustedcoin/__init__.py b/plugins/trustedcoin/__init__.py
       t@@ -7,5 +7,5 @@ description = ''.join([
            " <a href=\"https://api.trustedcoin.com/#/electrum-help\">https://api.trustedcoin.com/#/electrum-help</a>"
        ])
        requires_wallet_type = ['2fa']
       -registers_wallet_type = ('twofactor', '2fa', _("Wallet with two-factor authentication"))
       +registers_wallet_type = '2fa'
        available_for = ['qt']