From 688dd07381c28090dd0bbb6bb2b9c96fd7dc9ad0 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 27 Apr 2018 03:21:27 +0200 Subject: [PATCH 1/2] qt receive tab: show address on hw wallet --- plugins/digitalbitbox/digitalbitbox.py | 18 ++++++++++++++++-- plugins/digitalbitbox/qt.py | 2 +- plugins/hw_wallet/plugin.py | 17 +++++++++++++++++ plugins/hw_wallet/qt.py | 11 +++++++++++ plugins/keepkey/plugin.py | 10 +++++++++- plugins/ledger/ledger.py | 12 ++++++++++-- plugins/trezor/qt_generic.py | 2 +- plugins/trezor/trezor.py | 8 ++++++-- 8 files changed, 71 insertions(+), 9 deletions(-) diff --git a/plugins/digitalbitbox/digitalbitbox.py b/plugins/digitalbitbox/digitalbitbox.py index c0453ee4c..0129d0a79 100644 --- a/plugins/digitalbitbox/digitalbitbox.py +++ b/plugins/digitalbitbox/digitalbitbox.py @@ -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 _ @@ -737,7 +738,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) diff --git a/plugins/digitalbitbox/qt.py b/plugins/digitalbitbox/qt.py index 1978ce8cc..0d4512529 100644 --- a/plugins/digitalbitbox/qt.py +++ b/plugins/digitalbitbox/qt.py @@ -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) diff --git a/plugins/hw_wallet/plugin.py b/plugins/hw_wallet/plugin.py index 34573cf99..fe5086a17 100644 --- a/plugins/hw_wallet/plugin.py +++ b/plugins/hw_wallet/plugin.py @@ -26,6 +26,7 @@ from electrum.plugins import BasePlugin, hook from electrum.i18n import _ +from electrum.bitcoin import is_address class HW_PluginBase(BasePlugin): @@ -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 diff --git a/plugins/hw_wallet/qt.py b/plugins/hw_wallet/qt.py index 7c9fbeace..529dabbaf 100644 --- a/plugins/hw_wallet/qt.py +++ b/plugins/hw_wallet/qt.py @@ -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)) @@ -218,3 +219,13 @@ 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)) + # TODO icon + receive_address_e.addButton(":icons/tab_console.png", show_address, _("Show on {}").format(plugin.device)) diff --git a/plugins/keepkey/plugin.py b/plugins/keepkey/plugin.py index bd4b3b3da..3b52e6924 100644 --- a/plugins/keepkey/plugin.py +++ b/plugins/keepkey/plugin.py @@ -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 @@ -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")) diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py index e4a074d7e..8e31c6ece 100644 --- a/plugins/ledger/ledger.py +++ b/plugins/ledger/ledger.py @@ -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 @@ -597,7 +598,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) diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py index c2a76d82d..2e947f932 100644 --- a/plugins/trezor/qt_generic.py +++ b/plugins/trezor/qt_generic.py @@ -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 diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py index 3eb7008d4..218cca736 100644 --- a/plugins/trezor/trezor.py +++ b/plugins/trezor/trezor.py @@ -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 @@ -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")) From 78745f1f02afb6a6ded1699c7d56dc7c7bd4b1ef Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 28 Apr 2018 16:07:49 +0200 Subject: [PATCH 2/2] show address on hw: change icon --- icons.qrc | 1 + icons/eye1.png | Bin 0 -> 2910 bytes plugins/hw_wallet/qt.py | 3 +-- 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 icons/eye1.png diff --git a/icons.qrc b/icons.qrc index c709a0eb9..82cfba322 100644 --- a/icons.qrc +++ b/icons.qrc @@ -14,6 +14,7 @@ icons/electrum_light_icon.png icons/electrum_dark_icon.png icons/electrumb.png + icons/eye1.png icons/file.png icons/info.png icons/keepkey.png diff --git a/icons/eye1.png b/icons/eye1.png new file mode 100644 index 0000000000000000000000000000000000000000..0bded339f0f49f4ebb530dde10d07c60302e4e8f GIT binary patch literal 2910 zcmV-k3!(IhP)u5FtW@2oWMgh!7z{ga{ELMEHM0{Lt-{ zmM%_kY1J51mkCud0idW>6rEM)R=PKDezyaVKUjypPvbLZ-ZD~Zl^Y~X1||U$fw&>6 zbxOnm1-T#CFWlma$BAvJPQzFK2lBvluIYg?7R4eKy$GbZoKg>LtcLFGg64x1*H4rQF=WdkH@ci)yes|B zI*me6)@5W_;&He<*c|TgjR=88qs8rXVu(w`?X+X>Z1WcnXe(91T{(HOuE;<@En8m)7u6fE%7)$4UEzHK2_Po2yc`wszNh>2&+b#oEIyZ-658tyF~ z&y+DKj7d#kQjUd&b}Qd>^@MFpC<;gw)#JgGm_mE~NmP$FXt$NmXX@mM96wQw+wJ!G zajh!!bMkTuw^mml=@|9^6qhcVCM8=D_{VfnK|W7D_7K-!dkt^Cy^5BW^8jQ_xSp61 zDgL_CE>EQ>E6M+?D1y`kBkR^}q^qSKiHad6j)5~$C<<<;6QO93s>IsX06=?tC(9pL z%1t+1M^keP_2(LVRZ^s)-kLk+ian=J9y|AK{Q6c~)Qmah3nc6UMtU7kShBdBl`9@2 zGb0VF)kf8^6TO|*Fd{QApuRaKD#)fe#z@1_&!|7Vm*YFvaAfPdIBi{lozrN&BLRp{ z%L3sIQ2n_E8XB8POibkA2Y<~k?zs!CR_m*lDuviRqqMwiS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