electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 2f58d419dc8307c62478f6a171eafafb23d9127e
parent d150a6d29cbf01dfd3e4cb0cec13c46435f96099
Author: Neil Booth <kyuupichan@gmail.com>
Date:   Fri,  1 Jan 2016 18:38:43 +0900

Get ledger wallet working, for restore at least

Fixes #1592

Diffstat:
Mplugins/ledger/ledger.py | 46++++++++++++++++++++++++++--------------------
Mplugins/ledger/qt.py | 4+++-
Mplugins/trezor/plugin.py | 22++++++++++++++++++++++
Mplugins/trezor/qt_generic.py | 4----
4 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py @@ -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 - @hook - def close_wallet(self, wallet): - self.client = None + @staticmethod + def is_valid_seed(seed): + return True - @hook - def installwizard_load_wallet(self, wallet, window): - self.load_wallet(wallet, window) + def on_restore_wallet(self, wallet, wizard): + assert isinstance(wallet, self.wallet_class) - @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 + 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 diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py @@ -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: diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py @@ -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 diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py @@ -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: