mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
wallet.add_hw_info: also store "is_change" in output_info
as it seems every consumer wants to know this and has its own hacks to figure it out
This commit is contained in:
parent
ac329797e0
commit
ab76a1fe5b
8 changed files with 22 additions and 21 deletions
|
@ -99,7 +99,7 @@ class AddressSynchronizer(Logger):
|
|||
def synchronize(self):
|
||||
pass
|
||||
|
||||
def is_mine(self, address):
|
||||
def is_mine(self, address) -> bool:
|
||||
return self.db.is_addr_in_history(address)
|
||||
|
||||
def get_addresses(self):
|
||||
|
|
|
@ -132,14 +132,13 @@ class HW_PluginBase(BasePlugin):
|
|||
return self._ignore_outdated_fw
|
||||
|
||||
|
||||
def is_any_tx_output_on_change_branch(tx: Transaction):
|
||||
def is_any_tx_output_on_change_branch(tx: Transaction) -> bool:
|
||||
if not tx.output_info:
|
||||
return False
|
||||
for o in tx.outputs():
|
||||
info = tx.output_info.get(o.address)
|
||||
if info is not None:
|
||||
if info.address_index[0] == 1:
|
||||
return True
|
||||
return info.is_change
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -407,7 +407,7 @@ class KeepKeyPlugin(HW_PluginBase):
|
|||
|
||||
return inputs
|
||||
|
||||
def tx_outputs(self, derivation, tx):
|
||||
def tx_outputs(self, derivation, tx: Transaction):
|
||||
|
||||
def create_output_by_derivation():
|
||||
script_type = self.get_keepkey_output_script_type(info.script_type)
|
||||
|
@ -454,10 +454,9 @@ class KeepKeyPlugin(HW_PluginBase):
|
|||
info = tx.output_info.get(address)
|
||||
if info is not None and not has_change:
|
||||
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||
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:
|
||||
if info.is_change == any_output_on_change_branch:
|
||||
use_create_by_derivation = True
|
||||
has_change = True
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||
|
||||
@test_pin_unlocked
|
||||
@set_and_unset_signing
|
||||
def sign_transaction(self, tx, password):
|
||||
def sign_transaction(self, tx: Transaction, password):
|
||||
if tx.is_complete():
|
||||
return
|
||||
client = self.get_client()
|
||||
|
@ -409,10 +409,9 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||
if (info is not None) and len(tx.outputs()) > 1 \
|
||||
and not has_change:
|
||||
index = info.address_index
|
||||
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:
|
||||
if info.is_change == any_output_on_change_branch:
|
||||
changePath = self.get_derivation()[2:] + "/%d/%d"%index
|
||||
has_change = True
|
||||
else:
|
||||
|
|
|
@ -403,7 +403,7 @@ class SafeTPlugin(HW_PluginBase):
|
|||
|
||||
return inputs
|
||||
|
||||
def tx_outputs(self, derivation, tx):
|
||||
def tx_outputs(self, derivation, tx: Transaction):
|
||||
|
||||
def create_output_by_derivation():
|
||||
script_type = self.get_safet_output_script_type(info.script_type)
|
||||
|
@ -450,12 +450,11 @@ class SafeTPlugin(HW_PluginBase):
|
|||
info = tx.output_info.get(address)
|
||||
if info is not None and not has_change:
|
||||
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||
on_change_branch = index[0] == 1
|
||||
# prioritise hiding outputs on the 'change' branch from user
|
||||
# because no more than one change address allowed
|
||||
# note: ^ restriction can be removed once we require fw
|
||||
# that has https://github.com/trezor/trezor-mcu/pull/306
|
||||
if on_change_branch == any_output_on_change_branch:
|
||||
if info.is_change == any_output_on_change_branch:
|
||||
use_create_by_derivation = True
|
||||
has_change = True
|
||||
|
||||
|
|
|
@ -420,7 +420,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||
signatures=signatures,
|
||||
m=m)
|
||||
|
||||
def tx_outputs(self, derivation, tx):
|
||||
def tx_outputs(self, derivation, tx: Transaction):
|
||||
|
||||
def create_output_by_derivation():
|
||||
script_type = self.get_trezor_output_script_type(info.script_type)
|
||||
|
@ -455,12 +455,11 @@ class TrezorPlugin(HW_PluginBase):
|
|||
info = tx.output_info.get(address)
|
||||
if info is not None and not has_change:
|
||||
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||
on_change_branch = index[0] == 1
|
||||
# prioritise hiding outputs on the 'change' branch from user
|
||||
# because no more than one change address allowed
|
||||
# note: ^ restriction can be removed once we require fw
|
||||
# that has https://github.com/trezor/trezor-mcu/pull/306
|
||||
if on_change_branch == any_output_on_change_branch:
|
||||
if info.is_change == any_output_on_change_branch:
|
||||
use_create_by_derivation = True
|
||||
has_change = True
|
||||
|
||||
|
|
|
@ -81,9 +81,10 @@ class TxOutputForUI(NamedTuple):
|
|||
|
||||
class TxOutputHwInfo(NamedTuple):
|
||||
address_index: Tuple
|
||||
sorted_xpubs: Iterable[str]
|
||||
sorted_xpubs: Sequence[str]
|
||||
num_sig: Optional[int]
|
||||
script_type: str
|
||||
is_change: bool # whether the wallet considers the output to be change
|
||||
|
||||
|
||||
class BIP143SharedTxDigestFields(NamedTuple):
|
||||
|
|
|
@ -351,10 +351,10 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||
except:
|
||||
return
|
||||
|
||||
def is_mine(self, address):
|
||||
def is_mine(self, address) -> bool:
|
||||
return bool(self.get_address_index(address))
|
||||
|
||||
def is_change(self, address):
|
||||
def is_change(self, address) -> bool:
|
||||
if not self.is_mine(address):
|
||||
return False
|
||||
return self.get_address_index(address)[0]
|
||||
|
@ -1182,7 +1182,12 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||
# sort xpubs using the order of pubkeys
|
||||
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
|
||||
num_sig = self.m if isinstance(self, Multisig_Wallet) else None
|
||||
info[o.address] = TxOutputHwInfo(index, sorted_xpubs, num_sig, self.txin_type)
|
||||
is_change = self.is_change(o.address)
|
||||
info[o.address] = TxOutputHwInfo(address_index=index,
|
||||
sorted_xpubs=sorted_xpubs,
|
||||
num_sig=num_sig,
|
||||
script_type=self.txin_type,
|
||||
is_change=is_change)
|
||||
tx.output_info = info
|
||||
|
||||
def sign_transaction(self, tx, password):
|
||||
|
@ -1738,7 +1743,7 @@ class Imported_Wallet(Simple_Wallet):
|
|||
self.save_keystore()
|
||||
self.storage.write()
|
||||
|
||||
def is_mine(self, address):
|
||||
def is_mine(self, address) -> bool:
|
||||
return self.db.has_imported_address(address)
|
||||
|
||||
def get_address_index(self, address):
|
||||
|
|
Loading…
Add table
Reference in a new issue