simplify wallet types

This commit is contained in:
ThomasV 2016-08-19 17:26:57 +02:00
parent 058e49e839
commit 24a9ff3fef
4 changed files with 27 additions and 33 deletions

View File

@ -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
@ -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):
@ -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')

View File

@ -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

View File

@ -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
@ -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)
@ -1562,21 +1566,12 @@ class Wallet(object):
wallet = rwc(storage)
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

View File

@ -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']