commit 79f4a8bae970b8581dc069934d7ae6a390c79c90
parent 529cb3602cfdee710ff42a5e582f9d0bb8068901
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:
4 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/plugins/hw_wallet/plugin.py b/plugins/hw_wallet/plugin.py
@@ -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
diff --git a/plugins/keepkey/keepkey.py b/plugins/keepkey/keepkey.py
@@ -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
@@ -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
diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py
@@ -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
@@ -319,9 +320,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
signatures = []
preparedTrustedInputs = []
changePath = ""
- changeAmount = None
output = None
- outputAmount = None
p2shTransaction = False
segwitTransaction = False
pin = ""
@@ -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:
diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py
@@ -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
@@ -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