transaction.py: introduce TxOutputHwInfo namedtuple
This commit is contained in:
@@ -538,7 +538,7 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore):
|
|||||||
assert o.type == TYPE_ADDRESS
|
assert o.type == TYPE_ADDRESS
|
||||||
info = tx.output_info.get(o.address)
|
info = tx.output_info.get(o.address)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
index, xpubs, m = info
|
index = info.address_index
|
||||||
changePath = self.get_derivation() + "/%d/%d" % index
|
changePath = self.get_derivation() + "/%d/%d" % index
|
||||||
changePubkey = self.derive_pubkey(index[0], index[1])
|
changePubkey = self.derive_pubkey(index[0], index[1])
|
||||||
pubkeyarray_i = {'pubkey': changePubkey, 'keypath': changePath}
|
pubkeyarray_i = {'pubkey': changePubkey, 'keypath': changePath}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def is_any_tx_output_on_change_branch(tx):
|
|||||||
for _type, address, amount in tx.outputs():
|
for _type, address, amount in tx.outputs():
|
||||||
info = tx.output_info.get(address)
|
info = tx.output_info.get(address)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
index, xpubs, m = info
|
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||||
if index[0] == 1:
|
if index[0] == 1:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -351,8 +351,7 @@ class KeepKeyPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
def tx_outputs(self, derivation, tx, segwit=False):
|
def tx_outputs(self, derivation, tx, segwit=False):
|
||||||
|
|
||||||
def create_output_by_derivation(info):
|
def create_output_by_derivation():
|
||||||
index, xpubs, m = info
|
|
||||||
if len(xpubs) == 1:
|
if len(xpubs) == 1:
|
||||||
script_type = self.types.PAYTOP2SHWITNESS if segwit else self.types.PAYTOADDRESS
|
script_type = self.types.PAYTOP2SHWITNESS if segwit else self.types.PAYTOADDRESS
|
||||||
address_n = self.client_class.expand_path(derivation + "/%d/%d" % index)
|
address_n = self.client_class.expand_path(derivation + "/%d/%d" % index)
|
||||||
@@ -407,7 +406,7 @@ class KeepKeyPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
info = tx.output_info.get(address)
|
info = tx.output_info.get(address)
|
||||||
if info is not None and not has_change:
|
if info is not None and not has_change:
|
||||||
index, xpubs, m = info
|
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||||
on_change_branch = index[0] == 1
|
on_change_branch = index[0] == 1
|
||||||
# prioritise hiding outputs on the 'change' branch from user
|
# prioritise hiding outputs on the 'change' branch from user
|
||||||
# because no more than one change address allowed
|
# because no more than one change address allowed
|
||||||
@@ -416,7 +415,7 @@ class KeepKeyPlugin(HW_PluginBase):
|
|||||||
has_change = True
|
has_change = True
|
||||||
|
|
||||||
if use_create_by_derivation:
|
if use_create_by_derivation:
|
||||||
txoutputtype = create_output_by_derivation(info)
|
txoutputtype = create_output_by_derivation()
|
||||||
else:
|
else:
|
||||||
txoutputtype = create_output_by_address()
|
txoutputtype = create_output_by_address()
|
||||||
outputs.append(txoutputtype)
|
outputs.append(txoutputtype)
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
|||||||
info = tx.output_info.get(o.address)
|
info = tx.output_info.get(o.address)
|
||||||
if (info is not None) and len(tx.outputs()) > 1 \
|
if (info is not None) and len(tx.outputs()) > 1 \
|
||||||
and not has_change:
|
and not has_change:
|
||||||
index, xpubs, m = info
|
index = info.address_index
|
||||||
on_change_branch = index[0] == 1
|
on_change_branch = index[0] == 1
|
||||||
# prioritise hiding outputs on the 'change' branch from user
|
# prioritise hiding outputs on the 'change' branch from user
|
||||||
# because no more than one change address allowed
|
# because no more than one change address allowed
|
||||||
|
|||||||
@@ -413,8 +413,7 @@ class SafeTPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY):
|
def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY):
|
||||||
|
|
||||||
def create_output_by_derivation(info):
|
def create_output_by_derivation():
|
||||||
index, xpubs, m = info
|
|
||||||
if len(xpubs) == 1:
|
if len(xpubs) == 1:
|
||||||
if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
|
if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
|
||||||
script_type = self.types.OutputScriptType.PAYTOWITNESS
|
script_type = self.types.OutputScriptType.PAYTOWITNESS
|
||||||
@@ -469,7 +468,7 @@ class SafeTPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
info = tx.output_info.get(address)
|
info = tx.output_info.get(address)
|
||||||
if info is not None and not has_change:
|
if info is not None and not has_change:
|
||||||
index, xpubs, m = info
|
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||||
on_change_branch = index[0] == 1
|
on_change_branch = index[0] == 1
|
||||||
# prioritise hiding outputs on the 'change' branch from user
|
# prioritise hiding outputs on the 'change' branch from user
|
||||||
# because no more than one change address allowed
|
# because no more than one change address allowed
|
||||||
@@ -480,7 +479,7 @@ class SafeTPlugin(HW_PluginBase):
|
|||||||
has_change = True
|
has_change = True
|
||||||
|
|
||||||
if use_create_by_derivation:
|
if use_create_by_derivation:
|
||||||
txoutputtype = create_output_by_derivation(info)
|
txoutputtype = create_output_by_derivation()
|
||||||
else:
|
else:
|
||||||
txoutputtype = create_output_by_address()
|
txoutputtype = create_output_by_address()
|
||||||
outputs.append(txoutputtype)
|
outputs.append(txoutputtype)
|
||||||
|
|||||||
@@ -424,8 +424,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY):
|
def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY):
|
||||||
|
|
||||||
def create_output_by_derivation(info):
|
def create_output_by_derivation():
|
||||||
index, xpubs, m = info
|
|
||||||
if len(xpubs) == 1:
|
if len(xpubs) == 1:
|
||||||
if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
|
if script_gen == SCRIPT_GEN_NATIVE_SEGWIT:
|
||||||
script_type = self.types.OutputScriptType.PAYTOWITNESS
|
script_type = self.types.OutputScriptType.PAYTOWITNESS
|
||||||
@@ -480,7 +479,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
info = tx.output_info.get(address)
|
info = tx.output_info.get(address)
|
||||||
if info is not None and not has_change:
|
if info is not None and not has_change:
|
||||||
index, xpubs, m = info
|
index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig
|
||||||
on_change_branch = index[0] == 1
|
on_change_branch = index[0] == 1
|
||||||
# prioritise hiding outputs on the 'change' branch from user
|
# prioritise hiding outputs on the 'change' branch from user
|
||||||
# because no more than one change address allowed
|
# because no more than one change address allowed
|
||||||
@@ -491,7 +490,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
has_change = True
|
has_change = True
|
||||||
|
|
||||||
if use_create_by_derivation:
|
if use_create_by_derivation:
|
||||||
txoutputtype = create_output_by_derivation(info)
|
txoutputtype = create_output_by_derivation()
|
||||||
else:
|
else:
|
||||||
txoutputtype = create_output_by_address()
|
txoutputtype = create_output_by_address()
|
||||||
outputs.append(txoutputtype)
|
outputs.append(txoutputtype)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
# Note: The deserialization code originally comes from ABE.
|
# Note: The deserialization code originally comes from ABE.
|
||||||
|
|
||||||
from typing import Sequence, Union, NamedTuple
|
from typing import Sequence, Union, NamedTuple, Tuple, Optional, Iterable
|
||||||
|
|
||||||
from .util import print_error, profiler
|
from .util import print_error, profiler
|
||||||
|
|
||||||
@@ -63,6 +63,11 @@ TxOutput = NamedTuple("TxOutput", [('type', int), ('address', str), ('value', Un
|
|||||||
# ^ value is str when the output is set to max: '!'
|
# ^ value is str when the output is set to max: '!'
|
||||||
|
|
||||||
|
|
||||||
|
TxOutputHwInfo = NamedTuple("TxOutputHwInfo", [('address_index', Tuple),
|
||||||
|
('sorted_xpubs', Iterable[str]),
|
||||||
|
('num_sig', Optional[int])])
|
||||||
|
|
||||||
|
|
||||||
class BCDataStream(object):
|
class BCDataStream(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.input = None
|
self.input = None
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ from .keystore import load_keystore, Hardware_KeyStore
|
|||||||
from .storage import multisig_type, STO_EV_PLAINTEXT, STO_EV_USER_PW, STO_EV_XPUB_PW
|
from .storage import multisig_type, STO_EV_PLAINTEXT, STO_EV_USER_PW, STO_EV_XPUB_PW
|
||||||
|
|
||||||
from . import transaction, bitcoin, coinchooser, paymentrequest, contacts
|
from . import transaction, bitcoin, coinchooser, paymentrequest, contacts
|
||||||
from .transaction import Transaction, TxOutput
|
from .transaction import Transaction, TxOutput, TxOutputHwInfo
|
||||||
from .plugin import run_hook
|
from .plugin import run_hook
|
||||||
from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL,
|
from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL,
|
||||||
TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED)
|
TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED)
|
||||||
@@ -786,7 +786,8 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
pubkeys = self.get_public_keys(addr)
|
pubkeys = self.get_public_keys(addr)
|
||||||
# sort xpubs using the order of pubkeys
|
# sort xpubs using the order of pubkeys
|
||||||
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
|
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
|
||||||
info[addr] = index, sorted_xpubs, self.m if isinstance(self, Multisig_Wallet) else None
|
num_sig = self.m if isinstance(self, Multisig_Wallet) else None
|
||||||
|
info[addr] = TxOutputHwInfo(index, sorted_xpubs, num_sig)
|
||||||
tx.output_info = info
|
tx.output_info = info
|
||||||
|
|
||||||
def sign_transaction(self, tx, password):
|
def sign_transaction(self, tx, password):
|
||||||
|
|||||||
Reference in New Issue
Block a user