Trait bitcoins::prelude::Transaction [−][src]
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 Digest>::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.
Associated Types
An associated error type, used in Results returned by the Transaction.
type SighashArgs
type SighashArgs
A type describing arguments for the sighash function for this transaction.
type TXID: MarkedDigestOutput
type TXID: MarkedDigestOutput
A marked hash (see crate::hashes::marked) to be used as the transaction ID type.
type HashWriter: MarkedDigest<Self::TXID>
type HashWriter: MarkedDigest<Self::TXID>
A type that implements HashWriter
. Used to generate the TXID
and Sighash
.
Required methods
Instantiate a new Transaction by specifying inputs and outputs.
fn write_sighash_preimage<W>(
&self,
writer: &mut W,
_args: &Self::SighashArgs
) -> Result<(), Self::TxError> where
W: Write,
fn write_sighash_preimage<W>(
&self,
writer: &mut W,
_args: &Self::SighashArgs
) -> Result<(), Self::TxError> where
W: Write,
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.
fn sighash(
&self,
args: &Self::SighashArgs
) -> Result<GenericArray<u8, <Self::HashWriter as Digest>::OutputSize>, Self::TxError>
fn sighash(
&self,
args: &Self::SighashArgs
) -> Result<GenericArray<u8, <Self::HashWriter as Digest>::OutputSize>, Self::TxError>
Calls write_sighash_preimage
with the provided arguments and a new HashWriter.
Returns the sighash digest which should be signed.