mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Wallet: encapsulate wallet_types
Previously plugins would append lines to it and wizard.py would hack into it too.
This commit is contained in:
parent
151ac099a9
commit
b54ba556bc
3 changed files with 30 additions and 19 deletions
|
@ -27,7 +27,7 @@ import time
|
||||||
from util import *
|
from util import *
|
||||||
from i18n import _
|
from i18n import _
|
||||||
from util import profiler, PrintError, DaemonThread, UserCancelled
|
from util import profiler, PrintError, DaemonThread, UserCancelled
|
||||||
import wallet
|
|
||||||
|
|
||||||
class Plugins(DaemonThread):
|
class Plugins(DaemonThread):
|
||||||
|
|
||||||
|
@ -140,13 +140,16 @@ class Plugins(DaemonThread):
|
||||||
return wallet_types, descs
|
return wallet_types, descs
|
||||||
|
|
||||||
def register_plugin_wallet(self, name, gui_good, details):
|
def register_plugin_wallet(self, name, gui_good, details):
|
||||||
|
from wallet import Wallet
|
||||||
|
|
||||||
def dynamic_constructor(storage):
|
def dynamic_constructor(storage):
|
||||||
return self.wallet_plugin_loader(name).wallet_class(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)
|
||||||
self.print_error("registering wallet %s: %s" %(name, details))
|
self.print_error("registering wallet %s: %s" %(name, details))
|
||||||
wallet.wallet_types.append(details + (dynamic_constructor,))
|
Wallet.register_plugin_wallet(details[0], details[1],
|
||||||
|
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:
|
||||||
|
|
|
@ -27,6 +27,7 @@ import copy
|
||||||
import re
|
import re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
|
from collections import namedtuple
|
||||||
from i18n import _
|
from i18n import _
|
||||||
|
|
||||||
from util import NotEnoughFunds, PrintError, profiler
|
from util import NotEnoughFunds, PrintError, profiler
|
||||||
|
@ -1908,18 +1909,7 @@ class OldWallet(Deterministic_Wallet):
|
||||||
return ' '.join(old_mnemonic.mn_encode(s))
|
return ' '.join(old_mnemonic.mn_encode(s))
|
||||||
|
|
||||||
|
|
||||||
|
WalletType = namedtuple("WalletType", "category type constructor")
|
||||||
|
|
||||||
wallet_types = [
|
|
||||||
# category type description constructor
|
|
||||||
('standard', 'old', ("Old wallet"), OldWallet),
|
|
||||||
('standard', 'xpub', ("BIP32 Import"), BIP32_Simple_Wallet),
|
|
||||||
('standard', 'standard', ("Standard wallet"), NewWallet),
|
|
||||||
('standard', 'imported', ("Imported wallet"), Imported_Wallet),
|
|
||||||
('multisig', '2of2', ("Multisig wallet (2 of 2)"), Multisig_Wallet),
|
|
||||||
('multisig', '2of3', ("Multisig wallet (2 of 3)"), Multisig_Wallet),
|
|
||||||
('bip44', 'bip44', ("Restored hardware wallet"), BIP44_Wallet),
|
|
||||||
]
|
|
||||||
|
|
||||||
# former WalletFactory
|
# former WalletFactory
|
||||||
class Wallet(object):
|
class Wallet(object):
|
||||||
|
@ -1927,6 +1917,16 @@ class Wallet(object):
|
||||||
This class is actually a factory that will return a wallet of the correct
|
This class is actually a factory that will return a wallet of the correct
|
||||||
type when passed a WalletStorage instance."""
|
type when passed a WalletStorage instance."""
|
||||||
|
|
||||||
|
wallets = [ # category type constructor
|
||||||
|
WalletType('standard', 'old', OldWallet),
|
||||||
|
WalletType('standard', 'xpub', BIP32_Simple_Wallet),
|
||||||
|
WalletType('standard', 'standard', NewWallet),
|
||||||
|
WalletType('standard', 'imported', Imported_Wallet),
|
||||||
|
WalletType('multisig', '2of2', Multisig_Wallet),
|
||||||
|
WalletType('multisig', '2of3', Multisig_Wallet),
|
||||||
|
WalletType('bip44', 'bip44', BIP44_Wallet),
|
||||||
|
]
|
||||||
|
|
||||||
def __new__(self, storage):
|
def __new__(self, storage):
|
||||||
seed_version = storage.get('seed_version')
|
seed_version = storage.get('seed_version')
|
||||||
if not seed_version:
|
if not seed_version:
|
||||||
|
@ -1963,15 +1963,23 @@ class Wallet(object):
|
||||||
|
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def categories():
|
||||||
|
return [wallet.category for wallet in Wallet.wallets]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def register_plugin_wallet(category, type, constructor):
|
||||||
|
Wallet.wallets.append(WalletType(category, type, constructor))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def wallet_class(wallet_type, seed_version):
|
def wallet_class(wallet_type, seed_version):
|
||||||
if wallet_type:
|
if wallet_type:
|
||||||
if Wallet.multisig_type(wallet_type):
|
if Wallet.multisig_type(wallet_type):
|
||||||
return Multisig_Wallet
|
return Multisig_Wallet
|
||||||
|
|
||||||
for info in wallet_types:
|
for wallet in Wallet.wallets:
|
||||||
if wallet_type == info[1]:
|
if wallet.type == wallet_type:
|
||||||
return info[3]
|
return wallet.constructor
|
||||||
|
|
||||||
raise RuntimeError("Unknown wallet type: " + wallet_type)
|
raise RuntimeError("Unknown wallet type: " + wallet_type)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
from electrum import WalletStorage
|
from electrum import WalletStorage
|
||||||
from electrum.plugins import run_hook
|
from electrum.plugins import run_hook
|
||||||
from util import PrintError
|
from util import PrintError
|
||||||
from wallet import Wallet, wallet_types
|
from wallet import Wallet
|
||||||
from i18n import _
|
from i18n import _
|
||||||
|
|
||||||
MSG_GENERATING_WAIT = _("Electrum is generating your addresses, please wait...")
|
MSG_GENERATING_WAIT = _("Electrum is generating your addresses, please wait...")
|
||||||
|
@ -198,7 +198,7 @@ class WizardBase(PrintError):
|
||||||
self.remove_from_recently_open(storage.path)
|
self.remove_from_recently_open(storage.path)
|
||||||
|
|
||||||
# Filter out any unregistered wallet kinds
|
# Filter out any unregistered wallet kinds
|
||||||
registered_kinds = zip(*wallet_types)[0]
|
registered_kinds = Wallet.categories()
|
||||||
kinds, descriptions = zip(*[pair for pair in WizardBase.wallet_kinds
|
kinds, descriptions = zip(*[pair for pair in WizardBase.wallet_kinds
|
||||||
if pair[0] in registered_kinds])
|
if pair[0] in registered_kinds])
|
||||||
action, kind_index = self.query_create_or_restore(descriptions)
|
action, kind_index = self.query_create_or_restore(descriptions)
|
||||||
|
|
Loading…
Add table
Reference in a new issue