1
0

better integration of plugins in installwizard (for 2fa, trezor plugins)

This commit is contained in:
ThomasV
2014-07-01 18:46:11 +02:00
parent 101fe08ac8
commit 2c38e85a50
4 changed files with 156 additions and 207 deletions

View File

@@ -34,7 +34,7 @@ def run_hook(name, *args):
global plugins
found = 0
results = []
for p in plugins:
@@ -45,15 +45,15 @@ def run_hook(name, *args):
if not callable(f):
continue
found += 1
try:
f(*args)
r = f(*args)
except Exception:
print_error("Plugin error")
traceback.print_exc(file=sys.stdout)
return found
results.append((p.name,r))
return results

View File

@@ -1257,6 +1257,12 @@ class Deterministic_Wallet(Abstract_Wallet):
return False
return True
def get_action(self):
if not self.get_master_public_keys():
return 'create_seed'
if not self.accounts:
return 'create_accounts'
class NewWallet(Deterministic_Wallet):
@@ -1267,7 +1273,7 @@ class NewWallet(Deterministic_Wallet):
return self.accounts["m/0'"]
def is_watching_only(self):
return self.master_private_keys is {}
return not bool(self.master_private_keys)
def can_create_accounts(self):
return 'm/' in self.master_private_keys.keys()
@@ -1312,7 +1318,8 @@ class NewWallet(Deterministic_Wallet):
def create_accounts(self, password):
# First check the password is valid (this raises if it isn't).
self.check_password(password)
if not self.is_watching_only():
self.check_password(password)
self.create_account('Main account', password)
def add_master_public_key(self, name, xpub):
@@ -1419,7 +1426,7 @@ class Wallet_2of2(NewWallet):
def can_import(self):
return False
def create_account(self):
def create_account(self, name, password):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
account = BIP32_Account_2of2({'xpub':xpub1, 'xpub2':xpub2})
@@ -1434,9 +1441,11 @@ class Wallet_2of2(NewWallet):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
if xpub1 is None:
return 'create_2of2_1'
return 'create_seed'
if xpub2 is None:
return 'create_2of2_2'
return 'add_cosigner'
if not self.accounts:
return 'create_accounts'
class Wallet_2of3(Wallet_2of2):
@@ -1446,7 +1455,7 @@ class Wallet_2of3(Wallet_2of2):
Wallet_2of2.__init__(self, storage)
self.storage.put('wallet_type', '2of3', True)
def create_account(self):
def create_account(self, name, password):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
xpub3 = self.master_public_keys.get("remote/")
@@ -1463,13 +1472,12 @@ class Wallet_2of3(Wallet_2of2):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
xpub3 = self.master_public_keys.get("remote/")
# fixme: we use order of creation
if xpub2 and xpub1 is None:
return 'create_2fa_2'
if xpub1 is None:
return 'create_2of3_1'
return 'create_seed'
if xpub2 is None or xpub3 is None:
return 'create_2of3_2'
return 'add_two_cosigners'
if not self.accounts:
return 'create_accounts'
class OldWallet(Deterministic_Wallet):
@@ -1550,20 +1558,18 @@ class Wallet(object):
def __new__(self, storage):
config = storage.config
if config.get('bitkey', False):
# if user requested support for Bitkey device,
# import Bitkey driver
from wallet_bitkey import WalletBitkey
return WalletBitkey(config)
if storage.get('wallet_type') == '2of2':
return Wallet_2of2(storage)
self.wallet_types = [
('standard', ("Standard wallet"), OldWallet),
('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)
if storage.get('wallet_type') == '2of3':
return Wallet_2of3(storage)
if storage.get('wallet_type') == 'imported':
return Imported_Wallet(storage)
for t, l, WalletClass in self.wallet_types:
if t == storage.get('wallet_type'):
return WalletClass(storage)
if not storage.file_exists:
seed_version = NEW_SEED_VERSION if config.get('bip32') is True else OLD_SEED_VERSION

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from wallet import Wallet
#import bitkeylib.bitkey_pb2 as proto
from version import ELECTRUM_VERSION
SEED_VERSION = 4 # Version of bitkey algorithm
class WalletBitkey(Wallet):
pass