Exemple #1
0
    def tx_inputs(self, tx, xpub_path):
        inputs = []
        for txin in tx.inputs:
            txinputtype = TxInputType()
            txinputtype.prev_hash = bytes(reversed(txin.prev_hash))
            txinputtype.prev_index = txin.prev_idx
            txinputtype.sequence = txin.sequence
            txinputtype.amount = txin.value
            xpubs = [
                x_pubkey.bip32_extended_key_and_path()
                for x_pubkey in txin.x_pubkeys
            ]
            txinputtype.multisig = self._make_multisig(
                txin.threshold, xpubs, txin.stripped_signatures_with_blanks())
            txinputtype.script_type = self.get_trezor_input_script_type(
                txinputtype.multisig is not None)
            # find which key is mine
            for xpub, path in xpubs:
                if xpub in xpub_path:
                    xpub_n = bip32_decompose_chain_string(xpub_path[xpub])
                    txinputtype.address_n = xpub_n + path
                    break
            # if txin.script_sig:
            #     txinputtype.script_sig = bytes(txin.script_sig)
            inputs.append(txinputtype)

        return inputs
    def tx_inputs(self, tx: Transaction, *, for_sig=False, keystore: 'TrezorKeyStore' = None):
        inputs = []
        for txin in tx.inputs():
            if txin.is_coinbase_input():
                txinputtype = TxInputType(
                    prev_hash=b"\x00"*32,
                    prev_index=0xffffffff,  # signed int -1
                )
            else:
                txinputtype = TxInputType(
                    prev_hash=txin.prevout.txid,
                    prev_index=txin.prevout.out_idx,
                )
                if for_sig:
                    assert isinstance(tx, PartialTransaction)
                    assert isinstance(txin, PartialTxInput)
                    assert keystore
                    if len(txin.pubkeys) > 1:
                        xpubs_and_deriv_suffixes = get_xpubs_and_der_suffixes_from_txinout(tx, txin)
                        txinputtype.multisig = self._make_multisig(txin.num_sig, xpubs_and_deriv_suffixes)
                    txinputtype.script_type = self.get_trezor_input_script_type(txin.script_type)
                    my_pubkey, full_path = keystore.find_my_pubkey_in_txinout(txin)
                    if full_path:
                        txinputtype.address_n = full_path

            txinputtype.amount = txin.value_sats()
            txinputtype.script_sig = txin.script_sig
            txinputtype.sequence = txin.nsequence

            inputs.append(txinputtype)

        return inputs
Exemple #3
0
    def tx_inputs(self,
                  tx: Transaction,
                  xpub_path: Optional[Dict[str, str]] = None,
                  is_prev_tx: bool = False) -> List[TxInputType]:
        inputs = []
        for txin in tx.inputs:
            txinputtype = TxInputType()
            # Trezor tx hashes are same byte order as the reversed hex tx id.
            txinputtype.prev_hash = bytes(reversed(txin.prev_hash))
            txinputtype.prev_index = txin.prev_idx
            txinputtype.sequence = txin.sequence
            txinputtype.amount = txin.value
            if txin.script_sig:
                txinputtype.script_sig = bytes(txin.script_sig)
            if not is_prev_tx:
                assert xpub_path is not None, "no xpubs provided for hw signing operation"
                xpubs = [
                    x_pubkey.bip32_extended_key_and_path()
                    for x_pubkey in txin.x_pubkeys
                ]
                txinputtype.multisig = self._make_multisig(
                    txin.threshold, xpubs,
                    txin.stripped_signatures_with_blanks())
                txinputtype.script_type = self.get_trezor_input_script_type(
                    txinputtype.multisig is not None)
                # find which key is mine
                for xpub, path in xpubs:
                    if xpub in xpub_path:
                        xpub_n = tuple(
                            bip32_decompose_chain_string(xpub_path[xpub]))
                        # Sequences cannot be added according to mypy, annoying..
                        txinputtype.address_n = xpub_n + path  # type: ignore
                        break
            inputs.append(txinputtype)

        return inputs