Struct bitcoins::builder::BitcoinTxBuilder
source · [−]pub struct BitcoinTxBuilder<T: AddressEncoder> { /* private fields */ }
Expand description
This is a generic builder for Bitcoin transactions. It allows you to easily build legacy and witness transactions.
Note: due to Bitcoin consensus rules, the order of inputs and outputs may be semantically
meaningful. E.g. when signing a transaction with the SINGLE
sighash mode.
It is parameterized with an address encoder, so that the same struct and logic can be used on mainnet and testnet.
Implementations
sourceimpl<T> BitcoinTxBuilder<T> where
T: BitcoinEncoderMarker,
impl<T> BitcoinTxBuilder<T> where
T: BitcoinEncoderMarker,
sourcepub fn extend_witnesses<I>(self, witnesses: I) -> Self where
I: IntoIterator<Item = Witness>,
pub fn extend_witnesses<I>(self, witnesses: I) -> Self where
I: IntoIterator<Item = Witness>,
Add a set of witnesses to the transaction, and return a witness builder.
sourcepub fn insert_witness(
self,
index: usize,
witness: <<Self as TxBuilder>::Transaction as Transaction>::TxIn
) -> Self
pub fn insert_witness(
self,
index: usize,
witness: <<Self as TxBuilder>::Transaction as Transaction>::TxIn
) -> Self
Insert a witness at a speicified index
sourcepub fn op_return(self, message: &[u8]) -> Self
pub fn op_return(self, message: &[u8]) -> Self
Add an op_return output. Using this twice may render the transaction non-standard.
sourcepub fn set_script_sig(self, input_idx: usize, script_sig: ScriptSig) -> Self
pub fn set_script_sig(self, input_idx: usize, script_sig: ScriptSig) -> Self
Set the script sig at a specific input. Do nothing if the vin is not that long.
sourcepub fn build_legacy(
self
) -> Result<LegacyTx, <LegacyTx as Transaction>::TxError>
pub fn build_legacy(
self
) -> Result<LegacyTx, <LegacyTx as Transaction>::TxError>
Consume self, produce a legacy tx. Discard any witness information in the builder
sourcepub fn build_witness(
self
) -> Result<WitnessTx, <WitnessTx as Transaction>::TxError>
pub fn build_witness(
self
) -> Result<WitnessTx, <WitnessTx as Transaction>::TxError>
Consume self, produce a witness tx
sourcepub fn pay_script_pubkey(self, value: u64, script_pubkey: ScriptPubkey) -> Self
pub fn pay_script_pubkey(self, value: u64, script_pubkey: ScriptPubkey) -> Self
Add an output paying value
to script_pubkey
Trait Implementations
sourceimpl<T: Clone + AddressEncoder> Clone for BitcoinTxBuilder<T>
impl<T: Clone + AddressEncoder> Clone for BitcoinTxBuilder<T>
sourcefn clone(&self) -> BitcoinTxBuilder<T>
fn clone(&self) -> BitcoinTxBuilder<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug + AddressEncoder> Debug for BitcoinTxBuilder<T>
impl<T: Debug + AddressEncoder> Debug for BitcoinTxBuilder<T>
sourceimpl<T: PartialEq + AddressEncoder> PartialEq<BitcoinTxBuilder<T>> for BitcoinTxBuilder<T>
impl<T: PartialEq + AddressEncoder> PartialEq<BitcoinTxBuilder<T>> for BitcoinTxBuilder<T>
sourcefn eq(&self, other: &BitcoinTxBuilder<T>) -> bool
fn eq(&self, other: &BitcoinTxBuilder<T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &BitcoinTxBuilder<T>) -> bool
fn ne(&self, other: &BitcoinTxBuilder<T>) -> bool
This method tests for !=
.
sourceimpl<T> TxBuilder for BitcoinTxBuilder<T> where
T: BitcoinEncoderMarker,
impl<T> TxBuilder for BitcoinTxBuilder<T> where
T: BitcoinEncoderMarker,
type Encoder = T
type Encoder = T
An AddressEncoder that handles encoding and decoding network addresses. This is used in
the pay
function to decode addresses into associated RecipientIdentifier
s. Read more
type Transaction = BitcoinTx
type Transaction = BitcoinTx
The Transaction type returned by build()
sourcefn 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
sourcefn 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
sourcefn spend<I>(self, prevout: I, sequence: u32) -> Self where
I: Into<BitcoinOutpoint>,
fn spend<I>(self, prevout: I, sequence: u32) -> Self where
I: Into<BitcoinOutpoint>,
Spend an outpoint. Adds an unsigned input spending the associated outpoint with the specified sequence number. Read more
sourcefn pay(self, value: u64, address: &Address) -> Self
fn pay(self, value: u64, address: &Address) -> Self
Pay an Address. Adds an output paying value
to address.
sourcefn 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. Read more
sourcefn extend_inputs<I>(self, inputs: I) -> Self where
I: IntoIterator<Item = BitcoinTxIn>,
fn extend_inputs<I>(self, inputs: I) -> Self where
I: IntoIterator<Item = BitcoinTxIn>,
Add a set of inputs to the transaction.
sourcefn 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. Read more
sourcefn extend_outputs<I>(self, outputs: I) -> Self where
I: IntoIterator<Item = TxOut>,
fn extend_outputs<I>(self, outputs: I) -> Self where
I: IntoIterator<Item = TxOut>,
Add a set of outputs to the transaction.
sourcefn 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.
sourcefn 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
sourcefn 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
impl<T: Eq + AddressEncoder> Eq for BitcoinTxBuilder<T>
impl<T: AddressEncoder> StructuralEq for BitcoinTxBuilder<T>
impl<T: AddressEncoder> StructuralPartialEq for BitcoinTxBuilder<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for BitcoinTxBuilder<T>
impl<T> Send for BitcoinTxBuilder<T>
impl<T> Sync for BitcoinTxBuilder<T>
impl<T> Unpin for BitcoinTxBuilder<T>
impl<T> UnwindSafe for BitcoinTxBuilder<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more