pub trait Transaction: ByteFormat {
    type TxError: From<SerError> + From<Self::Error>;
    type TxIn: Input;
    type TxOut: Output;
    type SighashArgs;
    type TXID: MarkedDigestOutput;
    type HashWriter: MarkedDigest<Self::TXID>;

    fn new<I, O>(
        version: u32,
        vin: I,
        vout: O,
        locktime: u32
    ) -> Result<Self, Self::TxError>
    where
        I: Into<Vec<Self::TxIn, Global>>,
        O: Into<Vec<Self::TxOut, Global>>
; fn version(&self) -> u32; fn inputs(&self) -> &[Self::TxIn]; fn outputs(&self) -> &[Self::TxOut]; fn locktime(&self) -> u32; fn write_sighash_preimage<W>(
        &self,
        writer: &mut W,
        _args: &Self::SighashArgs
    ) -> Result<(), Self::TxError>
    where
        W: Write
; fn txid(&self) -> Self::TXID { ... } fn sighash(
        &self,
        args: &Self::SighashArgs
    ) -> Result<GenericArray<u8, <Self::HashWriter as OutputSizeUser>::OutputSize>, Self::TxError> { ... } }
Expand description

Basic functionality for a Transaction

This trait has been generalized to support transactions from Non-Bitcoin networks. The transaction specificies which types it considers to be inputs and outputs, and a struct that contains its Sighash arguments. This allows others to define custom transaction types with unique functionality.

Required Associated Types

An associated error type, used in Results returned by the Transaction.

The Input type for the transaction

The Output type for the transaction

A type describing arguments for the sighash function for this transaction.

A marked hash (see crate::hashes::marked) to be used as the transaction ID type.

A type that implements HashWriter. Used to generate the TXID and Sighash.

Required Methods

Instantiate a new Transaction by specifying inputs and outputs.

Returns the transaction version number

Returns a reference to the transaction input vector

Returns a reference the the transaction output vector

Returns the transaction’s nLocktime field

Generate the digest that must be signed to authorize inputs. For Bitcoin transactions this is a function of the transaction, and the input’s prevout.

Note:

For Bitcoin, this will write the DEFAULT sighash for the current transaction type. For witness transactions, that is the BIP143 sighash. When signing Legacy inputs included in a witness transaction, use write_legacy_sighash_preimage instead.

Provided Methods

Calculates and returns the transaction’s ID. The default TXID is simply the digest of the serialized transaction.

Calls write_sighash_preimage with the provided arguments and a new HashWriter. Returns the sighash digest which should be signed.

Implementors