Trait coins_core::builder::TxBuilder
source · [−]pub trait TxBuilder: Sized {
type Transaction: Transaction;
type Encoder: AddressEncoder;
Show 14 methods
fn new() -> Self;
fn from_tx_ref(tx: &Self::Transaction) -> Self;
fn from_tx(tx: Self::Transaction) -> Self;
fn version(self, version: u32) -> Self;
fn spend<I>(self, prevout: I, sequence: u32) -> Self
where
I: Into<<<Self::Transaction as Transaction>::TxIn as Input>::TxoIdentifier>;
fn pay(
self,
value: <<Self::Transaction as Transaction>::TxOut as Output>::Value,
address: &<Self::Encoder as AddressEncoder>::Address
) -> Self;
fn insert_input(
self,
index: usize,
input: <Self::Transaction as Transaction>::TxIn
) -> Self;
fn extend_inputs<I>(self, inputs: I) -> Self
where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxIn>;
fn insert_output(
self,
index: usize,
output: <Self::Transaction as Transaction>::TxOut
) -> Self;
fn extend_outputs<I>(self, outputs: I) -> Self
where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxOut>;
fn locktime(self, locktime: u32) -> Self;
fn build(
self
) -> Result<Self::Transaction, <Self::Transaction as Transaction>::TxError>;
fn read_from_tx<R>(
reader: &mut R
) -> Result<Self, <Self::Transaction as Transaction>::TxError>
where
R: Read,
{ ... }
fn from_hex_tx(
hex_str: &str
) -> Result<Self, <Self::Transaction as Transaction>::TxError> { ... }
}
Expand description
A builder-pattern interface for constructing transactions. Implementations should accumulate
inputs, outputs, witnesses, and other TX data, and then build()
a Transaction object from
the accumulated data.
Required Associated Types
type Transaction: Transaction
type Transaction: Transaction
The Transaction type returned by build()
type Encoder: AddressEncoder
type Encoder: AddressEncoder
An AddressEncoder that handles encoding and decoding network addresses. This is used in
the pay
function to decode addresses into associated RecipientIdentifier
s.
Required Methods
fn from_tx_ref(tx: &Self::Transaction) -> Self
fn from_tx_ref(tx: &Self::Transaction) -> Self
Instantiate a new builder from a transaction reference by cloning its properties
fn from_tx(tx: Self::Transaction) -> Self
fn from_tx(tx: Self::Transaction) -> Self
Instantiate a new builder from a transaction by taking ownership of its properties
Set or overwrite the transaction version.
If implementing a network without a version field, feel free to leave this as a NOP
fn spend<I>(self, prevout: I, sequence: u32) -> Self where
I: Into<<<Self::Transaction as Transaction>::TxIn as Input>::TxoIdentifier>,
fn spend<I>(self, prevout: I, sequence: u32) -> Self where
I: Into<<<Self::Transaction as Transaction>::TxIn as Input>::TxoIdentifier>,
Spend an outpoint. Adds an unsigned input spending the associated outpoint with the specified sequence number.
fn pay(
self,
value: <<Self::Transaction as Transaction>::TxOut as Output>::Value,
address: &<Self::Encoder as AddressEncoder>::Address
) -> Self
fn pay(
self,
value: <<Self::Transaction as Transaction>::TxOut as Output>::Value,
address: &<Self::Encoder as AddressEncoder>::Address
) -> Self
Pay an Address. Adds an output paying value
to address.
fn insert_input(
self,
index: usize,
input: <Self::Transaction as Transaction>::TxIn
) -> Self
fn insert_input(
self,
index: usize,
input: <Self::Transaction as Transaction>::TxIn
) -> Self
Insert an input at the specified index. Inputs after that are shifted to later indices.
Note
This may invalidate signatures made using ANYONECANPAY.
fn extend_inputs<I>(self, inputs: I) -> Self where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxIn>,
fn extend_inputs<I>(self, inputs: I) -> Self where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxIn>,
Add a set of inputs to the transaction.
fn insert_output(
self,
index: usize,
output: <Self::Transaction as Transaction>::TxOut
) -> Self
fn insert_output(
self,
index: usize,
output: <Self::Transaction as Transaction>::TxOut
) -> Self
Insert an output at the specified index. Outputs after that are shifted to later indices.
Note
This may invalidate signatures made using SINGLE.
fn extend_outputs<I>(self, outputs: I) -> Self where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxOut>,
fn extend_outputs<I>(self, outputs: I) -> Self where
I: IntoIterator<Item = <Self::Transaction as Transaction>::TxOut>,
Add a set of outputs to the transaction.
Set or overwrite the transaction locktime.
If implementing a network without a locktime field, feel free to leave this as a NOP
fn build(
self
) -> Result<Self::Transaction, <Self::Transaction as Transaction>::TxError>
fn build(
self
) -> Result<Self::Transaction, <Self::Transaction as Transaction>::TxError>
Consume the builder and produce a transaction from the builder’s current state.
Provided Methods
fn read_from_tx<R>(
reader: &mut R
) -> Result<Self, <Self::Transaction as Transaction>::TxError> where
R: Read,
fn read_from_tx<R>(
reader: &mut R
) -> Result<Self, <Self::Transaction as Transaction>::TxError> where
R: Read,
Instantiate a new builder from a std::io::Read
that contains a serialized tx
fn from_hex_tx(
hex_str: &str
) -> Result<Self, <Self::Transaction as Transaction>::TxError>
fn from_hex_tx(
hex_str: &str
) -> Result<Self, <Self::Transaction as Transaction>::TxError>
Instantiate a new builder from transaction hex