[wallet] Overhaul TxBuilder internals and externals
Fixes #251 TxBuilders are now not created directly but are created through the wallet with `build_tx` and `build_fee_bump`. The advantages of this realised in this commit are: 1. Normal tx creation and fee bumping use the code internally. The only difference between normal tx and fee bump is how the builder is created. 2. The TxBuilder now has a refernce to the wallet and can therefore lookup things as methods are called on it. `add_utxo` now uses this to look up UTXO deta when it is called (rather than having to do it and possibly error later on). To support these changes `get_utxo` and `get_descriptor_for_keychain` public methods have been added to Wallet. I could have kept them pub(crate) but they seem like fine APIs to have publicly.
This commit is contained in:
@@ -27,15 +27,12 @@
|
||||
//! This module provides the trait [`CoinSelectionAlgorithm`] that can be implemented to
|
||||
//! define custom coin selection algorithms.
|
||||
//!
|
||||
//! The coin selection algorithm is not globally part of a [`Wallet`](super::Wallet), instead it
|
||||
//! is selected whenever a [`Wallet::create_tx`](super::Wallet::create_tx) call is made, through
|
||||
//! the use of the [`TxBuilder`] structure, specifically with
|
||||
//! [`TxBuilder::coin_selection`](super::tx_builder::TxBuilder::coin_selection) method.
|
||||
//!
|
||||
//! The [`DefaultCoinSelectionAlgorithm`] selects the default coin selection algorithm that
|
||||
//! [`TxBuilder`] uses, if it's not explicitly overridden.
|
||||
//! You can specify a custom coin selection algorithm through the [`coin_selection`] method on
|
||||
//! [`TxBuilder`]. [`DefaultCoinSelectionAlgorithm`] aliases the coin selection algorithm that will
|
||||
//! be used if it is not explicitly set.
|
||||
//!
|
||||
//! [`TxBuilder`]: super::tx_builder::TxBuilder
|
||||
//! [`coin_selection`]: super::tx_builder::coin_selection
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
@@ -88,10 +85,9 @@
|
||||
//! // create wallet, sync, ...
|
||||
//!
|
||||
//! let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap();
|
||||
//! let (psbt, details) = wallet.create_tx(
|
||||
//! TxBuilder::with_recipients(vec![(to_address.script_pubkey(), 50_000)])
|
||||
//! .coin_selection(AlwaysSpendEverything),
|
||||
//! )?;
|
||||
//! let (psbt, details) = wallet.build_tx().coin_selection(AlwaysSpendEverything)
|
||||
//! .add_recipient(to_address.script_pubkey(), 50_000)
|
||||
//! .finish()?;
|
||||
//!
|
||||
//! // inspect, sign, broadcast, ...
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user