commit 1d513358277bd77332c809b7fd67382bb0aaeea2
parent 84450b9189f49c23aaae47ecdb80652085b9c582
Author: Neil Booth <kyuupichan@gmail.com>
Date: Wed, 30 Dec 2015 17:03:26 +0900
Remove need for self.wallet for h/w wallets
Diffstat:
9 files changed, 38 insertions(+), 71 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -1537,7 +1537,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
if any(can_send(addr) for addr in addrs):
menu.addAction(_("Send From"), lambda: self.send_from_addresses(addrs))
- run_hook('receive_menu', menu, addrs)
+ run_hook('receive_menu', menu, addrs, self.wallet)
menu.exec_(self.address_list.viewport().mapToGlobal(position))
diff --git a/lib/plugins.py b/lib/plugins.py
@@ -137,8 +137,6 @@ def _run_hook(name, always, *args):
results = []
f_list = hooks.get(name, [])
for p, f in f_list:
- if name == 'load_wallet':
- p.wallet = args[0] # For for p.is_enabled() below
if always or p.is_enabled():
try:
r = f(*args)
diff --git a/plugins/keepkey/cmdline.py b/plugins/keepkey/cmdline.py
@@ -25,8 +25,6 @@ class KeepKeyCmdLineHandler:
class Plugin(KeepKeyPlugin):
@hook
def cmdline_load_wallet(self, wallet):
- self.wallet = wallet
- self.wallet.plugin = self
+ wallet.plugin = self
if self.handler is None:
self.handler = KeepKeyCmdLineHandler()
-
diff --git a/plugins/ledger/cmdline.py b/plugins/ledger/cmdline.py
@@ -20,9 +20,6 @@ class BTChipCmdLineHandler:
class Plugin(LedgerPlugin):
@hook
def cmdline_load_wallet(self, wallet):
- self.wallet = wallet
- self.wallet.plugin = self
+ wallet.plugin = self
if self.handler is None:
self.handler = BTChipCmdLineHandler()
-
-
diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py
@@ -261,8 +261,6 @@ class BTChipWallet(BIP32_HD_Wallet):
return BIP32_HD_Wallet.sign_transaction(self, tx, password)
if tx.is_complete():
return
- #if tx.error:
- # raise BaseException(tx.error)
self.signing = True
inputs = []
inputsPaths = []
@@ -421,33 +419,24 @@ class LedgerPlugin(BasePlugin):
def __init__(self, parent, config, name):
BasePlugin.__init__(self, parent, config, name)
- self.wallet = None
self.handler = None
def constructor(self, s):
return BTChipWallet(s)
def is_enabled(self):
- if not BTCHIP:
- return False
- if not self.wallet:
- return False
- if self.wallet.storage.get('wallet_type') != 'btchip':
- return False
- if self.wallet.has_seed():
- return False
- return True
+ return BTCHIP:
- def btchip_is_connected(self):
+ def btchip_is_connected(self, wallet):
try:
- self.wallet.get_client().getFirmwareVersion()
+ wallet.get_client().getFirmwareVersion()
except:
return False
return True
@hook
def close_wallet(self):
- self.wallet = None
+ pass
@hook
def installwizard_load_wallet(self, wallet, window):
@@ -466,11 +455,3 @@ class LedgerPlugin(BasePlugin):
QMessageBox.information(None, _('Error'), str(e), _('OK'))
return
return wallet
-
- @hook
- def sign_tx(self, window, tx):
- tx.error = None
- try:
- self.wallet.sign_transaction(tx, None)
- except Exception as e:
- tx.error = str(e)
diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py
@@ -4,23 +4,24 @@ import threading
from electrum.plugins import BasePlugin, hook
-from ledger import LedgerPlugin
+from ledger import LedgerPlugin, BTChipWallet
class Plugin(LedgerPlugin):
@hook
def load_wallet(self, wallet, window):
- self.wallet = wallet
- self.wallet.plugin = self
+ if type(wallet) != BTChipWallet:
+ return
+ wallet.plugin = self
if self.handler is None:
self.handler = BTChipQTHandler(window)
- if self.btchip_is_connected():
- if not self.wallet.check_proper_device():
+ if self.btchip_is_connected(wallet):
+ if not wallet.check_proper_device():
window.show_error(_("This wallet does not match your Ledger device"))
- self.wallet.force_watching_only = True
+ wallet.force_watching_only = True
else:
window.show_error(_("Ledger device not detected.\nContinuing in watching-only mode."))
- self.wallet.force_watching_only = True
+ wallet.force_watching_only = True
class BTChipQTHandler:
diff --git a/plugins/trezor/cmdline.py b/plugins/trezor/cmdline.py
@@ -27,8 +27,8 @@ class Plugin(TrezorPlugin):
@hook
def cmdline_load_wallet(self, wallet):
- self.wallet = wallet
- self.wallet.plugin = self
+ if type(wallet) != self.wallet_class:
+ return
+ wallet.plugin = self
if self.handler is None:
self.handler = TrezorCmdLineHandler()
-
diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py
@@ -113,7 +113,7 @@ class TrezorCompatibleWallet(BIP44_Wallet):
acc_id = re.match("x/(\d+)'", k).group(1)
xpub_path[xpub] = self.account_derivation(acc_id)
- self.plugin.sign_transaction(tx, prev_tx, xpub_path)
+ self.plugin.sign_transaction(self, tx, prev_tx, xpub_path)
def is_proper_device(self):
self.get_client().ping('t')
@@ -154,7 +154,6 @@ class TrezorCompatiblePlugin(BasePlugin):
def __init__(self, parent, config, name):
BasePlugin.__init__(self, parent, config, name)
self.device = self.wallet_class.device
- self.wallet = None
self.handler = None
self.client = None
@@ -166,16 +165,7 @@ class TrezorCompatiblePlugin(BasePlugin):
raise Exception(message)
def is_enabled(self):
- if not self.libraries_available:
- return False
- if not self.wallet:
- return False
- wallet_type = self.wallet_class.wallet_type
- if self.wallet.storage.get('wallet_type') != wallet_type:
- return False
- if self.wallet.has_seed():
- return False
- return True
+ return self.libraries_available
def create_client(self):
if not self.libraries_available:
@@ -212,14 +202,13 @@ class TrezorCompatiblePlugin(BasePlugin):
self.client.clear_session()
self.client.transport.close()
self.client = None
- self.wallet = None
- def sign_transaction(self, tx, prev_tx, xpub_path):
+ def sign_transaction(self, wallet, tx, prev_tx, xpub_path):
self.prev_tx = prev_tx
self.xpub_path = xpub_path
client = self.get_client()
inputs = self.tx_inputs(tx, True)
- outputs = self.tx_outputs(tx)
+ outputs = self.tx_outputs(wallet, tx)
try:
signed_tx = client.sign_tx('Bitcoin', inputs, outputs)[1]
except Exception as e:
@@ -229,11 +218,11 @@ class TrezorCompatiblePlugin(BasePlugin):
raw = signed_tx.encode('hex')
tx.update_signatures(raw)
- def show_address(self, address):
+ def show_address(self, wallet, address):
client = self.get_client()
- self.wallet.check_proper_device()
+ wallet.check_proper_device()
try:
- address_path = self.wallet.address_id(address)
+ address_path = wallet.address_id(address)
address_n = client.expand_path(address_path)
except Exception as e:
self.give_error(e)
@@ -306,15 +295,15 @@ class TrezorCompatiblePlugin(BasePlugin):
return inputs
- def tx_outputs(self, tx):
+ def tx_outputs(self, wallet, tx):
client = self.get_client()
outputs = []
for type, address, amount in tx.outputs:
assert type == 'address'
txoutputtype = self.types.TxOutputType()
- if self.wallet.is_change(address):
- address_path = self.wallet.address_id(address)
+ if wallet.is_change(address):
+ address_path = wallet.address_id(address)
address_n = client.expand_path(address_path)
txoutputtype.address_n.extend(address_n)
else:
diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py
@@ -108,16 +108,17 @@ class QtPlugin(TrezorPlugin):
@hook
def load_wallet(self, wallet, window):
+ if type(wallet) != self.wallet_class:
+ return
self.print_error("load_wallet")
- self.wallet = wallet
- self.wallet.plugin = self
+ wallet.plugin = self
self.button = StatusBarButton(QIcon(self.icon_file), self.device,
partial(self.settings_dialog, window))
if type(window) is ElectrumWindow:
window.statusBar().addPermanentWidget(self.button)
if self.handler is None:
self.handler = self.create_handler(window)
- msg = self.wallet.sanity_check()
+ msg = wallet.sanity_check()
if msg:
window.show_error(msg)
@@ -139,7 +140,7 @@ class QtPlugin(TrezorPlugin):
# Restored wallets are not hardware wallets
wallet_class = self.wallet_class.restore_wallet_class
storage.put('wallet_type', wallet_class.wallet_type)
- self.wallet = wallet = wallet_class(storage)
+ wallet = wallet_class(storage)
handler = self.create_handler(wizard)
msg = "\n".join([_("Please enter your %s passphrase.") % self.device,
@@ -154,11 +155,13 @@ class QtPlugin(TrezorPlugin):
return wallet
@hook
- def receive_menu(self, menu, addrs):
- if (not self.wallet.is_watching_only() and
+ def receive_menu(self, menu, addrs, wallet):
+ if type(wallet) != self.wallet_class:
+ return
+ if (not wallet.is_watching_only() and
self.atleast_version(1, 3) and len(addrs) == 1):
menu.addAction(_("Show on %s") % self.device,
- lambda: self.show_address(addrs[0]))
+ lambda: self.show_address(wallet, addrs[0]))
def settings_dialog(self, window):