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: return info.is_change return False
def is_any_tx_output_on_change_branch(tx: Transaction): 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 False
def tx_outputs(self, derivation, tx: Transaction): def create_output_by_derivation(): script_type = self.get_trezor_output_script_type(info.script_type) deriv = parse_path("/%d/%d" % index) multisig = self._make_multisig(m, [(xpub, deriv) for xpub in xpubs]) txoutputtype = TxOutputType(multisig=multisig, amount=amount, address_n=parse_path(derivation + "/%d/%d" % index), script_type=script_type) return txoutputtype def create_output_by_address(): txoutputtype = TxOutputType() txoutputtype.amount = amount if _type == TYPE_SCRIPT: txoutputtype.script_type = OutputScriptType.PAYTOOPRETURN txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data( o) elif _type == TYPE_ADDRESS: txoutputtype.script_type = OutputScriptType.PAYTOADDRESS txoutputtype.address = address return txoutputtype outputs = [] has_change = False any_output_on_change_branch = is_any_tx_output_on_change_branch(tx) for o in tx.outputs(): _type, address, amount = o.type, o.address, o.value use_create_by_derivation = False 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 # 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 info.is_change == any_output_on_change_branch: use_create_by_derivation = True has_change = True if use_create_by_derivation: txoutputtype = create_output_by_derivation() else: txoutputtype = create_output_by_address() outputs.append(txoutputtype) return outputs