qt receive tab: show address on hw wallet
This commit is contained in:
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import electrum
|
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.bitcoin import serialize_xpub, deserialize_xpub
|
||||||
|
from electrum.wallet import Standard_Wallet
|
||||||
from electrum import constants
|
from electrum import constants
|
||||||
from electrum.transaction import Transaction
|
from electrum.transaction import Transaction
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
@@ -737,7 +738,20 @@ class DigitalBitboxPlugin(HW_PluginBase):
|
|||||||
client.check_device_dialog()
|
client.check_device_dialog()
|
||||||
return client
|
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)
|
change, index = wallet.get_address_index(address)
|
||||||
keypath = '%s/%d/%d' % (keystore.derivation, change, index)
|
keypath = '%s/%d/%d' % (keystore.derivation, change, index)
|
||||||
xpub = self.get_client(keystore)._get_xpub(keypath)
|
xpub = self.get_client(keystore)._get_xpub(keypath)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Plugin(DigitalBitboxPlugin, QtPluginBase):
|
|||||||
|
|
||||||
if len(addrs) == 1:
|
if len(addrs) == 1:
|
||||||
def show_address():
|
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)
|
menu.addAction(_("Show on {}").format(self.device), show_address)
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
from electrum.plugins import BasePlugin, hook
|
from electrum.plugins import BasePlugin, hook
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
from electrum.bitcoin import is_address
|
||||||
|
|
||||||
|
|
||||||
class HW_PluginBase(BasePlugin):
|
class HW_PluginBase(BasePlugin):
|
||||||
@@ -58,3 +59,19 @@ class HW_PluginBase(BasePlugin):
|
|||||||
uninitialized, go through the initialization process.
|
uninitialized, go through the initialization process.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
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
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ class QtPluginBase(object):
|
|||||||
handler.button = button
|
handler.button = button
|
||||||
keystore.handler = handler
|
keystore.handler = handler
|
||||||
keystore.thread = TaskThread(window, window.on_error)
|
keystore.thread = TaskThread(window, window.on_error)
|
||||||
|
self.add_show_address_on_hw_device_button_for_receive_addr(wallet, keystore, window)
|
||||||
# Trigger a pairing
|
# Trigger a pairing
|
||||||
keystore.thread.add(partial(self.get_client, keystore))
|
keystore.thread.add(partial(self.get_client, keystore))
|
||||||
|
|
||||||
@@ -218,3 +219,13 @@ class QtPluginBase(object):
|
|||||||
|
|
||||||
def show_settings_dialog(self, window, keystore):
|
def show_settings_dialog(self, window, keystore):
|
||||||
device_id = self.choose_device(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))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from electrum.i18n import _
|
|||||||
from electrum.plugins import BasePlugin
|
from electrum.plugins import BasePlugin
|
||||||
from electrum.transaction import deserialize, Transaction
|
from electrum.transaction import deserialize, Transaction
|
||||||
from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey
|
from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey
|
||||||
|
from electrum.wallet import Standard_Wallet
|
||||||
from electrum.base_wizard import ScriptTypeNotSupported
|
from electrum.base_wizard import ScriptTypeNotSupported
|
||||||
|
|
||||||
from ..hw_wallet import HW_PluginBase
|
from ..hw_wallet import HW_PluginBase
|
||||||
@@ -224,7 +225,14 @@ class KeepKeyCompatiblePlugin(HW_PluginBase):
|
|||||||
raw = bh2u(signed_tx)
|
raw = bh2u(signed_tx)
|
||||||
tx.update_signatures(raw)
|
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)
|
client = self.get_client(wallet.keystore)
|
||||||
if not client.atleast_version(1, 3):
|
if not client.atleast_version(1, 3):
|
||||||
wallet.keystore.handler.show_error(_("Your device firmware is too old"))
|
wallet.keystore.handler.show_error(_("Your device firmware is too old"))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from electrum.i18n import _
|
|||||||
from electrum.plugins import BasePlugin
|
from electrum.plugins import BasePlugin
|
||||||
from electrum.keystore import Hardware_KeyStore
|
from electrum.keystore import Hardware_KeyStore
|
||||||
from electrum.transaction import Transaction
|
from electrum.transaction import Transaction
|
||||||
|
from electrum.wallet import Standard_Wallet
|
||||||
from ..hw_wallet import HW_PluginBase
|
from ..hw_wallet import HW_PluginBase
|
||||||
from electrum.util import print_error, is_verbose, bfh, bh2u, versiontuple
|
from electrum.util import print_error, is_verbose, bfh, bh2u, versiontuple
|
||||||
|
|
||||||
@@ -597,7 +598,14 @@ class LedgerPlugin(HW_PluginBase):
|
|||||||
client.checkDevice()
|
client.checkDevice()
|
||||||
return client
|
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)
|
sequence = wallet.get_address_index(address)
|
||||||
txin_type = wallet.get_txin_type(address)
|
txin_type = wallet.get_txin_type(address)
|
||||||
wallet.get_keystore().show_address(sequence, txin_type)
|
keystore.show_address(sequence, txin_type)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class QtPlugin(QtPluginBase):
|
|||||||
for keystore in wallet.get_keystores():
|
for keystore in wallet.get_keystores():
|
||||||
if type(keystore) == self.keystore_class:
|
if type(keystore) == self.keystore_class:
|
||||||
def show_address():
|
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)
|
menu.addAction(_("Show on {}").format(self.device), show_address)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from binascii import hexlify, unhexlify
|
|||||||
|
|
||||||
from electrum.util import bfh, bh2u, versiontuple
|
from electrum.util import bfh, bh2u, versiontuple
|
||||||
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
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 import constants
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.plugins import BasePlugin, Device
|
from electrum.plugins import BasePlugin, Device
|
||||||
@@ -271,7 +271,11 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
raw = bh2u(signed_tx)
|
raw = bh2u(signed_tx)
|
||||||
tx.update_signatures(raw)
|
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)
|
client = self.get_client(keystore)
|
||||||
if not client.atleast_version(1, 3):
|
if not client.atleast_version(1, 3):
|
||||||
keystore.handler.show_error(_("Your device firmware is too old"))
|
keystore.handler.show_error(_("Your device firmware is too old"))
|
||||||
|
|||||||
Reference in New Issue
Block a user