tledger: support hiding outputs on 'receive' branch - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 79f4a8bae970b8581dc069934d7ae6a390c79c90 DIR parent 529cb3602cfdee710ff42a5e582f9d0bb8068901 HTML Author: SomberNight <somber.night@protonmail.com> Date: Fri, 15 Jun 2018 20:48:57 +0200 ledger: support hiding outputs on 'receive' branch so if change is on the 'receive' branch, user won't be prompted to confirm it Diffstat: M plugins/hw_wallet/plugin.py | 12 ++++++++++++ M plugins/keepkey/keepkey.py | 12 ++---------- M plugins/ledger/ledger.py | 22 +++++++++++++++------- M plugins/trezor/trezor.py | 12 ++---------- 4 files changed, 31 insertions(+), 27 deletions(-) --- DIR diff --git a/plugins/hw_wallet/plugin.py b/plugins/hw_wallet/plugin.py t@@ -75,3 +75,15 @@ class HW_PluginBase(BasePlugin): if type(keystore) != self.keystore_class: return False return True + + +def is_any_tx_output_on_change_branch(tx): + if not hasattr(tx, 'output_info'): + return False + for _type, address, amount in tx.outputs(): + info = tx.output_info.get(address) + if info is not None: + index, xpubs, m = info + if index[0] == 1: + return True + return False DIR diff --git a/plugins/keepkey/keepkey.py b/plugins/keepkey/keepkey.py t@@ -15,6 +15,7 @@ from electrum.wallet import Standard_Wallet from electrum.base_wizard import ScriptTypeNotSupported from ..hw_wallet import HW_PluginBase +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch # TREZOR initialization methods t@@ -393,18 +394,9 @@ class KeepKeyPlugin(HW_PluginBase): txoutputtype.address = address return txoutputtype - def is_any_output_on_change_branch(): - for _type, address, amount in tx.outputs(): - info = tx.output_info.get(address) - if info is not None: - index, xpubs, m = info - if index[0] == 1: - return True - return False - outputs = [] has_change = False - any_output_on_change_branch = is_any_output_on_change_branch() + any_output_on_change_branch = is_any_tx_output_on_change_branch(tx) for _type, address, amount in tx.outputs(): use_create_by_derivation = False DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -11,6 +11,7 @@ from electrum.keystore import Hardware_KeyStore from electrum.transaction import Transaction from electrum.wallet import Standard_Wallet from ..hw_wallet import HW_PluginBase +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch from electrum.util import print_error, is_verbose, bfh, bh2u, versiontuple from electrum.base_wizard import ScriptTypeNotSupported t@@ -319,9 +320,7 @@ class Ledger_KeyStore(Hardware_KeyStore): signatures = [] preparedTrustedInputs = [] changePath = "" - changeAmount = None output = None - outputAmount = None p2shTransaction = False segwitTransaction = False pin = "" t@@ -386,22 +385,31 @@ class Ledger_KeyStore(Hardware_KeyStore): txOutput += script txOutput = bfh(txOutput) - # Recognize outputs - only one output and one change is authorized + # Recognize outputs + # - only one output and one change is authorized (for hw.1 and nano) + # - at most one output can bypass confirmation (~change) (for all) if not p2shTransaction: if not self.get_client_electrum().supports_multi_output(): if len(tx.outputs()) > 2: self.give_error("Transaction with more than 2 outputs not supported") + has_change = False + any_output_on_change_branch = is_any_tx_output_on_change_branch(tx) for _type, address, amount in tx.outputs(): assert _type == TYPE_ADDRESS info = tx.output_info.get(address) if (info is not None) and len(tx.outputs()) > 1 \ - and info[0][0] == 1: # "is on 'change' branch" + and not has_change: index, xpubs, m = info - changePath = self.get_derivation()[2:] + "/%d/%d"%index - changeAmount = amount + on_change_branch = index[0] == 1 + # prioritise hiding outputs on the 'change' branch from user + # because no more than one change address allowed + if on_change_branch == any_output_on_change_branch: + changePath = self.get_derivation()[2:] + "/%d/%d"%index + has_change = True + else: + output = address else: output = address - outputAmount = amount self.handler.show_message(_("Confirm Transaction on your Ledger device...")) try: DIR diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py t@@ -13,6 +13,7 @@ from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey, xtyp from electrum.base_wizard import ScriptTypeNotSupported from ..hw_wallet import HW_PluginBase +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch # TREZOR initialization methods t@@ -466,18 +467,9 @@ class TrezorPlugin(HW_PluginBase): txoutputtype.address = address return txoutputtype - def is_any_output_on_change_branch(): - for _type, address, amount in tx.outputs(): - info = tx.output_info.get(address) - if info is not None: - index, xpubs, m = info - if index[0] == 1: - return True - return False - outputs = [] has_change = False - any_output_on_change_branch = is_any_output_on_change_branch() + any_output_on_change_branch = is_any_tx_output_on_change_branch(tx) for _type, address, amount in tx.outputs(): use_create_by_derivation = False