[−][src]Struct bdk::wallet::tx_builder::TxBuilder
A transaction builder
This structure contains the configuration that the wallet must follow to build a transaction.
For an example see this module's documentation;
Implementations
impl<D: Database, Ctx: TxBuilderContext> TxBuilder<D, DefaultCoinSelectionAlgorithm, Ctx>
[src]
impl<D: Database, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderContext> TxBuilder<D, Cs, Ctx>
[src]
pub fn fee_rate(self, fee_rate: FeeRate) -> Self
[src]
Set a custom fee rate
pub fn fee_absolute(self, fee_amount: u64) -> Self
[src]
Set an absolute fee
pub fn policy_path(
self,
policy_path: BTreeMap<String, Vec<usize>>,
keychain: KeychainKind
) -> Self
[src]
self,
policy_path: BTreeMap<String, Vec<usize>>,
keychain: KeychainKind
) -> Self
Set the policy path to use while creating the transaction for a given keychain.
This method accepts a map where the key is the policy node id (see
Policy::id
) and the value is the list of the indexes of
the items that are intended to be satisfied from the policy node (see
SatisfiableItem::Thresh::items
).
Example
An example of when the policy path is needed is the following descriptor:
wsh(thresh(2,pk(A),sj:and_v(v:pk(B),n:older(6)),snj:and_v(v:pk(C),after(630000))))
,
derived from the miniscript policy thresh(2,pk(A),and(pk(B),older(6)),and(pk(C),after(630000)))
.
It declares three descriptor fragments, and at the top level it uses thresh()
to
ensure that at least two of them are satisfied. The individual fragments are:
pk(A)
and(pk(B),older(6))
and(pk(C),after(630000))
When those conditions are combined in pairs, it's clear that the transaction needs to be created differently depending on how the user intends to satisfy the policy afterwards:
- If fragments
1
and2
are used, the transaction will need to use a specificn_sequence
in order to spend anOP_CSV
branch. - If fragments
1
and3
are used, the transaction will need to use a specificlocktime
in order to spend anOP_CLTV
branch. - If fragments
2
and3
are used, the transaction will need both.
When the spending policy is represented as a tree (see
Wallet::policies
), every node
is assigned a unique identifier that can be used in the policy path to specify which of
the node's children the user intends to satisfy: for instance, assuming the thresh()
root node of this example has an id of aabbccdd
, the policy path map would look like:
{ "aabbccdd" => [0, 1] }
where the key is the node's id, and the value is a list of the children that should be used, in no particular order.
If a particularly complex descriptor has multiple ambiguous thresholds in its structure, multiple entries can be added to the map, one for each node that requires an explicit path.
let mut path = BTreeMap::new(); path.insert("aabbccdd".to_string(), vec![0, 1]); let builder = TxBuilder::with_recipients(vec![(to_address.script_pubkey(), 50_000)]) .policy_path(path, KeychainKind::External);
pub fn utxos(self, utxos: Vec<OutPoint>) -> Self
[src]
Replace the internal list of utxos that must be spent with a new list
These have priority over the "unspendable" utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent.
pub fn add_utxo(self, utxo: OutPoint) -> Self
[src]
Add a utxo to the internal list of utxos that must be spent
These have priority over the "unspendable" utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent.
pub fn manually_selected_only(self) -> Self
[src]
Only spend utxos added by add_utxo
and utxos
.
The wallet will not add additional utxos to the transaction even if they are needed to make the transaction valid.
pub fn unspendable(self, unspendable: Vec<OutPoint>) -> Self
[src]
Replace the internal list of unspendable utxos with a new list
It's important to note that the "must-be-spent" utxos added with TxBuilder::utxos
and
TxBuilder::add_utxo
have priority over these. See the docs of the two linked methods
for more details.
pub fn add_unspendable(self, unspendable: OutPoint) -> Self
[src]
Add a utxo to the internal list of unspendable utxos
It's important to note that the "must-be-spent" utxos added with TxBuilder::utxos
and
TxBuilder::add_utxo
have priority over this. See the docs of the two linked methods
for more details.
pub fn sighash(self, sighash: SigHashType) -> Self
[src]
Sign with a specific sig hash
Use this option very carefully
pub fn ordering(self, ordering: TxOrdering) -> Self
[src]
Choose the ordering for inputs and outputs of the transaction
pub fn nlocktime(self, locktime: u32) -> Self
[src]
Use a specific nLockTime while creating the transaction
This can cause conflicts if the wallet's descriptors contain an "after" (OP_CLTV) operator.
pub fn version(self, version: i32) -> Self
[src]
Build a transaction with a specific version
The version
should always be greater than 0
and greater than 1
if the wallet's
descriptors contain an "older" (OP_CSV) operator.
pub fn do_not_spend_change(self) -> Self
[src]
Do not spend change outputs
This effectively adds all the change outputs to the "unspendable" list. See
TxBuilder::unspendable
.
pub fn only_spend_change(self) -> Self
[src]
Only spend change outputs
This effectively adds all the non-change outputs to the "unspendable" list. See
TxBuilder::unspendable
.
pub fn change_policy(self, change_policy: ChangeSpendPolicy) -> Self
[src]
Set a specific ChangeSpendPolicy
. See TxBuilder::do_not_spend_change
and
TxBuilder::only_spend_change
for some shortcuts.
pub fn force_non_witness_utxo(self) -> Self
[src]
Fill-in the psbt::Input::non_witness_utxo
field even if the wallet only has SegWit
descriptors.
This is useful for signers which always require it, like Trezor hardware wallets.
pub fn include_output_redeem_witness_script(self) -> Self
[src]
Fill-in the psbt::Output::redeem_script
and
psbt::Output::witness_script
fields.
This is useful for signers which always require it, like ColdCard hardware wallets.
pub fn add_global_xpubs(self) -> Self
[src]
Fill-in the PSBT_GLOBAL_XPUB
field with the extended keys contained in both the external
and internal descriptors
This is useful for offline signers that take part to a multisig. Some hardware wallets like BitBox and ColdCard are known to require this.
pub fn drain_wallet(self) -> Self
[src]
Spend all the available inputs. This respects filters like TxBuilder::unspendable
and the change policy.
pub fn coin_selection<P: CoinSelectionAlgorithm<D>>(
self,
coin_selection: P
) -> TxBuilder<D, P, Ctx>
[src]
self,
coin_selection: P
) -> TxBuilder<D, P, Ctx>
Choose the coin selection algorithm
Overrides the DefaultCoinSelectionAlgorithm
.
impl<D: Database> TxBuilder<D, DefaultCoinSelectionAlgorithm, CreateTx>
[src]
pub fn with_recipients(recipients: Vec<(Script, u64)>) -> Self
[src]
Create a builder starting from a list of recipients
impl<D: Database, Cs: CoinSelectionAlgorithm<D>> TxBuilder<D, Cs, CreateTx>
[src]
pub fn set_recipients(self, recipients: Vec<(Script, u64)>) -> Self
[src]
Replace the recipients already added with a new list
pub fn add_recipient(self, script_pubkey: Script, amount: u64) -> Self
[src]
Add a recipient to the internal list
pub fn set_single_recipient(self, recipient: Script) -> Self
[src]
Set a single recipient that will get all the selected funds minus the fee. No change will be created
This method overrides any recipient set with set_recipients
or
add_recipient
.
It can only be used in conjunction with drain_wallet
to send the
entire content of the wallet (minus filters) to a single recipient or with a
list of manually selected UTXOs by enabling manually_selected_only
and selecting them with utxos
or add_utxo
.
When bumping the fees of a transaction made with this option, the user should remeber to
add maintain_single_recipient
to correctly update the
single output instead of adding one more for the change.
pub fn enable_rbf(self) -> Self
[src]
Enable signaling RBF
This will use the default nSequence value of 0xFFFFFFFD
.
pub fn enable_rbf_with_sequence(self, nsequence: u32) -> Self
[src]
Enable signaling RBF with a specific nSequence value
This can cause conflicts if the wallet's descriptors contain an "older" (OP_CSV) operator
and the given nsequence
is lower than the CSV value.
If the nsequence
is higher than 0xFFFFFFFD
an error will be thrown, since it would not
be a valid nSequence to signal RBF.
impl<D: Database> TxBuilder<D, DefaultCoinSelectionAlgorithm, BumpFee>
[src]
pub fn maintain_single_recipient(self) -> Self
[src]
Bump the fees of a transaction made with set_single_recipient
Unless extra inputs are specified with add_utxo
or utxos
, this flag will make
bump_fee
reduce the value of the existing output, or fail if it would be consumed
entirely given the higher new fee rate.
If extra inputs are added and they are not entirely consumed in fees, a change output will not be added; the existing output will simply grow in value.
Fails if the transaction has more than one outputs.
Trait Implementations
impl<D: Debug + Database, Cs: Debug + CoinSelectionAlgorithm<D>, Ctx: Debug + TxBuilderContext> Debug for TxBuilder<D, Cs, Ctx>
[src]
impl<D: Database, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderContext> Default for TxBuilder<D, Cs, Ctx> where
Cs: Default,
[src]
Cs: Default,
Auto Trait Implementations
impl<D, Cs, Ctx> RefUnwindSafe for TxBuilder<D, Cs, Ctx> where
Cs: RefUnwindSafe,
Ctx: RefUnwindSafe,
D: RefUnwindSafe,
[src]
Cs: RefUnwindSafe,
Ctx: RefUnwindSafe,
D: RefUnwindSafe,
impl<D, Cs, Ctx> Send for TxBuilder<D, Cs, Ctx> where
Cs: Send,
Ctx: Send,
D: Send,
[src]
Cs: Send,
Ctx: Send,
D: Send,
impl<D, Cs, Ctx> Sync for TxBuilder<D, Cs, Ctx> where
Cs: Sync,
Ctx: Sync,
D: Sync,
[src]
Cs: Sync,
Ctx: Sync,
D: Sync,
impl<D, Cs, Ctx> Unpin for TxBuilder<D, Cs, Ctx> where
Cs: Unpin,
Ctx: Unpin,
D: Unpin,
[src]
Cs: Unpin,
Ctx: Unpin,
D: Unpin,
impl<D, Cs, Ctx> UnwindSafe for TxBuilder<D, Cs, Ctx> where
Cs: UnwindSafe,
Ctx: UnwindSafe,
D: UnwindSafe,
[src]
Cs: UnwindSafe,
Ctx: UnwindSafe,
D: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,