tMerge pull request #4316 from SomberNight/receive_tab_show_address - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 40e9e8bd632bd3d600d8913788221d60a3801cc1 DIR parent 33e3170591ef28d25b01fde8ab49a7781637abd6 HTML Author: ghost43 <somber.night@protonmail.com> Date: Sat, 28 Apr 2018 16:36:40 +0200 Merge pull request #4316 from SomberNight/receive_tab_show_address t[Qt] receive tab: show address on hw wallet Diffstat: M icons.qrc | 1 + A icons/eye1.png | 0 M plugins/digitalbitbox/digitalbitbo… | 18 ++++++++++++++++-- M plugins/digitalbitbox/qt.py | 2 +- M plugins/hw_wallet/plugin.py | 17 +++++++++++++++++ M plugins/hw_wallet/qt.py | 10 ++++++++++ M plugins/keepkey/plugin.py | 10 +++++++++- M plugins/ledger/ledger.py | 12 ++++++++++-- M plugins/trezor/qt_generic.py | 2 +- M plugins/trezor/trezor.py | 8 ++++++-- 10 files changed, 71 insertions(+), 9 deletions(-) --- DIR diff --git a/icons.qrc b/icons.qrc t@@ -14,6 +14,7 @@ <file>icons/electrum_light_icon.png</file> <file>icons/electrum_dark_icon.png</file> <file>icons/electrumb.png</file> + <file>icons/eye1.png</file> <file>icons/file.png</file> <file>icons/info.png</file> <file>icons/keepkey.png</file> DIR diff --git a/icons/eye1.png b/icons/eye1.png Binary files differ. DIR diff --git a/plugins/digitalbitbox/digitalbitbox.py b/plugins/digitalbitbox/digitalbitbox.py t@@ -5,8 +5,9 @@ try: import electrum - from electrum.bitcoin import TYPE_ADDRESS, push_script, var_int, msg_magic, Hash, verify_message, pubkey_from_signature, point_to_ser, public_key_to_p2pkh, EncodeAES, DecodeAES, MyVerifyingKey + from electrum.bitcoin import TYPE_ADDRESS, push_script, var_int, msg_magic, Hash, verify_message, pubkey_from_signature, point_to_ser, public_key_to_p2pkh, EncodeAES, DecodeAES, MyVerifyingKey, is_address from electrum.bitcoin import serialize_xpub, deserialize_xpub + from electrum.wallet import Standard_Wallet from electrum import constants from electrum.transaction import Transaction from electrum.i18n import _ t@@ -738,7 +739,20 @@ class DigitalBitboxPlugin(HW_PluginBase): client.check_device_dialog() return client - def show_address(self, wallet, keystore, address): + def show_address(self, wallet, address, keystore=None): + if keystore is None: + keystore = wallet.get_keystore() + if not self.show_address_helper(wallet, address, keystore): + return + if type(wallet) is not Standard_Wallet: + keystore.handler.show_error(_('This function is only available for standard wallets when using {}.').format(self.device)) + return + if not self.is_mobile_paired(): + keystore.handler.show_error(_('This function is only available after pairing your {} with a mobile device.').format(self.device)) + return + if not keystore.is_p2pkh(): + keystore.handler.show_error(_('This function is only available for p2pkh keystores when using {}.').format(self.device)) + return change, index = wallet.get_address_index(address) keypath = '%s/%d/%d' % (keystore.derivation, change, index) xpub = self.get_client(keystore)._get_xpub(keypath) DIR diff --git a/plugins/digitalbitbox/qt.py b/plugins/digitalbitbox/qt.py t@@ -32,7 +32,7 @@ class Plugin(DigitalBitboxPlugin, QtPluginBase): if len(addrs) == 1: def show_address(): - keystore.thread.add(partial(self.show_address, wallet, keystore, addrs[0])) + keystore.thread.add(partial(self.show_address, wallet, addrs[0], keystore)) menu.addAction(_("Show on {}").format(self.device), show_address) DIR diff --git a/plugins/hw_wallet/plugin.py b/plugins/hw_wallet/plugin.py t@@ -26,6 +26,7 @@ from electrum.plugins import BasePlugin, hook from electrum.i18n import _ +from electrum.bitcoin import is_address class HW_PluginBase(BasePlugin): t@@ -58,3 +59,19 @@ class HW_PluginBase(BasePlugin): uninitialized, go through the initialization process. """ raise NotImplementedError() + + def show_address(self, wallet, address, keystore=None): + pass # implemented in child classes + + def show_address_helper(self, wallet, address, keystore=None): + if keystore is None: + keystore = wallet.get_keystore() + if not is_address(address): + keystore.handler.show_error(_('Invalid Bitcoin Address')) + return False + if not wallet.is_mine(address): + keystore.handler.show_error(_('Address not in wallet.')) + return False + if type(keystore) != self.keystore_class: + return False + return True DIR diff --git a/plugins/hw_wallet/qt.py b/plugins/hw_wallet/qt.py t@@ -201,6 +201,7 @@ class QtPluginBase(object): handler.button = button keystore.handler = handler keystore.thread = TaskThread(window, window.on_error) + self.add_show_address_on_hw_device_button_for_receive_addr(wallet, keystore, window) # Trigger a pairing keystore.thread.add(partial(self.get_client, keystore)) t@@ -218,3 +219,12 @@ class QtPluginBase(object): def show_settings_dialog(self, window, keystore): device_id = self.choose_device(window, keystore) + + def add_show_address_on_hw_device_button_for_receive_addr(self, wallet, keystore, main_window): + plugin = keystore.plugin + receive_address_e = main_window.receive_address_e + + def show_address(): + addr = receive_address_e.text() + keystore.thread.add(partial(plugin.show_address, wallet, addr, keystore)) + receive_address_e.addButton(":icons/eye1.png", show_address, _("Show on {}").format(plugin.device)) DIR diff --git a/plugins/keepkey/plugin.py b/plugins/keepkey/plugin.py t@@ -9,6 +9,7 @@ from electrum.i18n import _ from electrum.plugins import BasePlugin from electrum.transaction import deserialize, Transaction from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey +from electrum.wallet import Standard_Wallet from electrum.base_wizard import ScriptTypeNotSupported from ..hw_wallet import HW_PluginBase t@@ -224,7 +225,14 @@ class KeepKeyCompatiblePlugin(HW_PluginBase): raw = bh2u(signed_tx) tx.update_signatures(raw) - def show_address(self, wallet, address): + def show_address(self, wallet, address, keystore=None): + if keystore is None: + keystore = wallet.get_keystore() + if not self.show_address_helper(wallet, address, keystore): + return + if type(wallet) is not Standard_Wallet: + keystore.handler.show_error(_('This function is only available for standard wallets when using {}.').format(self.device)) + return client = self.get_client(wallet.keystore) if not client.atleast_version(1, 3): wallet.keystore.handler.show_error(_("Your device firmware is too old")) DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -9,6 +9,7 @@ from electrum.i18n import _ from electrum.plugins import BasePlugin from electrum.keystore import Hardware_KeyStore from electrum.transaction import Transaction +from electrum.wallet import Standard_Wallet from ..hw_wallet import HW_PluginBase from electrum.util import print_error, is_verbose, bfh, bh2u, versiontuple t@@ -602,7 +603,14 @@ class LedgerPlugin(HW_PluginBase): client.checkDevice() return client - def show_address(self, wallet, address): + def show_address(self, wallet, address, keystore=None): + if keystore is None: + keystore = wallet.get_keystore() + if not self.show_address_helper(wallet, address, keystore): + return + if type(wallet) is not Standard_Wallet: + keystore.handler.show_error(_('This function is only available for standard wallets when using {}.').format(self.device)) + return sequence = wallet.get_address_index(address) txin_type = wallet.get_txin_type(address) - wallet.get_keystore().show_address(sequence, txin_type) + keystore.show_address(sequence, txin_type) DIR diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py t@@ -193,7 +193,7 @@ class QtPlugin(QtPluginBase): for keystore in wallet.get_keystores(): if type(keystore) == self.keystore_class: def show_address(): - keystore.thread.add(partial(self.show_address, wallet, keystore, addrs[0])) + keystore.thread.add(partial(self.show_address, wallet, addrs[0], keystore)) menu.addAction(_("Show on {}").format(self.device), show_address) break DIR diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py t@@ -2,7 +2,7 @@ from binascii import hexlify, unhexlify from electrum.util import bfh, bh2u, versiontuple from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, - TYPE_ADDRESS, TYPE_SCRIPT) + TYPE_ADDRESS, TYPE_SCRIPT, is_address) from electrum import constants from electrum.i18n import _ from electrum.plugins import BasePlugin, Device t@@ -271,7 +271,11 @@ class TrezorPlugin(HW_PluginBase): raw = bh2u(signed_tx) tx.update_signatures(raw) - def show_address(self, wallet, keystore, address): + def show_address(self, wallet, address, keystore=None): + if keystore is None: + keystore = wallet.get_keystore() + if not self.show_address_helper(wallet, address, keystore): + return client = self.get_client(keystore) if not client.atleast_version(1, 3): keystore.handler.show_error(_("Your device firmware is too old"))