mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
ledger: support hiding outputs on 'receive' branch
so if change is on the 'receive' branch, user won't be prompted to confirm it
This commit is contained in:
parent
529cb3602c
commit
79f4a8bae9
4 changed files with 31 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
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
|
||||
changeAmount = amount
|
||||
has_change = True
|
||||
else:
|
||||
output = address
|
||||
else:
|
||||
output = address
|
||||
outputAmount = amount
|
||||
|
||||
self.handler.show_message(_("Confirm Transaction on your Ledger device..."))
|
||||
try:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue