Get ledger wallet working, for restore at least

Fixes #1592
This commit is contained in:
Neil Booth 2016-01-01 18:38:43 +09:00
parent d150a6d29c
commit 2f58d419dc
4 changed files with 51 additions and 25 deletions

View File

@ -32,6 +32,7 @@ except ImportError:
class BTChipWallet(BIP32_HD_Wallet):
wallet_type = 'btchip'
device = 'Ledger'
root_derivation = "m/44'/0'"
restore_wallet_class = BIP44_Wallet
@ -55,10 +56,6 @@ class BTChipWallet(BIP32_HD_Wallet):
self.device_checked = False
raise Exception(message)
def get_action(self):
if not self.accounts:
return 'create_accounts'
def can_sign_xpubkey(self, x_pubkey):
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
return xpub in self.master_public_keys.values()
@ -418,6 +415,8 @@ class LedgerPlugin(BasePlugin):
def __init__(self, parent, config, name):
BasePlugin.__init__(self, parent, config, name)
self.wallet_class.plugin = self
self.device = self.wallet_class.device
self.handler = None
def constructor(self, s):
@ -433,22 +432,29 @@ class LedgerPlugin(BasePlugin):
return False
return True
@staticmethod
def is_valid_seed(seed):
return True
def on_restore_wallet(self, wallet, wizard):
assert isinstance(wallet, self.wallet_class)
msg = _("Enter the seed for your %s wallet:" % self.device)
seed = wizard.request_seed(msg, is_valid = self.is_valid_seed)
# Restored wallets are not hardware wallets
wallet_class = self.wallet_class.restore_wallet_class
wallet.storage.put('wallet_type', wallet_class.wallet_type)
wallet = wallet_class(wallet.storage)
# Ledger wallets don't use passphrases
passphrase = unicode()
password = wizard.request_password()
wallet.add_seed(seed, password)
wallet.add_cosigner_seed(seed, 'x/', password, passphrase)
wallet.create_main_account(password)
return wallet
@hook
def close_wallet(self, wallet):
self.client = None
@hook
def installwizard_load_wallet(self, wallet, window):
self.load_wallet(wallet, window)
@hook
def installwizard_restore(self, wizard, storage):
if storage.get('wallet_type') != 'btchip':
return
wallet = BTChipWallet(storage)
try:
wallet.create_main_account(None)
except BaseException as e:
QMessageBox.information(None, _('Error'), str(e), _('OK'))
return
return wallet

View File

@ -12,7 +12,6 @@ class Plugin(LedgerPlugin):
def load_wallet(self, wallet, window):
if type(wallet) != BTChipWallet:
return
wallet.plugin = self
if self.handler is None:
self.handler = BTChipQTHandler(window)
if self.btchip_is_connected(wallet):
@ -23,6 +22,9 @@ class Plugin(LedgerPlugin):
window.show_error(_("Ledger device not detected.\nContinuing in watching-only mode."))
wallet.force_watching_only = True
def on_create_wallet(self, wallet, wizard):
self.handler = BTChipQTHandler(wizard)
wallet.create_main_account(None)
class BTChipQTHandler:

View File

@ -335,3 +335,25 @@ class TrezorCompatiblePlugin(BasePlugin):
tx = self.prev_tx[tx_hash]
tx.deserialize()
return self.electrum_tx_to_txtype(tx)
@staticmethod
def is_valid_seed(seed):
return True
def on_restore_wallet(self, wallet, wizard):
assert isinstance(wallet, self.wallet_class)
msg = _("Enter the seed for your %s wallet:" % self.device)
seed = wizard.request_seed(msg, is_valid = self.is_valid_seed)
# Restored wallets are not hardware wallets
wallet_class = self.wallet_class.restore_wallet_class
wallet.storage.put('wallet_type', wallet_class.wallet_type)
wallet = wallet_class(wallet.storage)
passphrase = wizard.request_passphrase(self.device, restore=True)
password = wizard.request_password()
wallet.add_seed(seed, password)
wallet.add_cosigner_seed(seed, 'x/', password, passphrase)
wallet.create_main_account(password)
return wallet

View File

@ -125,10 +125,6 @@ class QtPlugin(TrezorPlugin):
client.handler = self.create_handler(wizard)
wallet.create_main_account(None)
@staticmethod
def is_valid_seed(seed):
return True
@hook
def receive_menu(self, menu, addrs, wallet):
if type(wallet) != self.wallet_class: