pub struct InputSelection<F = ()> {
pub max_inputs: Option<usize>,
pub exclude: HashSet<VtxoId>,
/* private fields */
}Expand description
Parameters controlling which VTXOs may be selected as inputs for a payment.
Builder pattern is used. By default there is no limit on the number of inputs and no VTXOs are excluded.
use bitcoin::Amount;
use bark::vtxo::selection::InputSelection;
let selected = InputSelection::new()
.max_inputs(10) // use at most 10 VTXOs
.exclude(poisoned) // never select this one
.select(vtxos, Amount::from_sat(100_000))?;Adding a fee scheme with InputSelection::fee_scheme makes InputSelection::select also cover the fee charged on top of the amount and return it alongside the VTXOs.
Fields§
§max_inputs: Option<usize>Cap on the total number of inputs that may be selected.
exclude: HashSet<VtxoId>Never select these vtxos.
Implementations§
Source§impl<F> InputSelection<F>
impl<F> InputSelection<F>
Sourcepub fn max_inputs(self, max_inputs: usize) -> Self
pub fn max_inputs(self, max_inputs: usize) -> Self
Cap the total number of inputs that may be selected.
Sourcepub fn exclude_many(self, exclude: impl IntoIterator<Item = VtxoId>) -> Self
pub fn exclude_many(self, exclude: impl IntoIterator<Item = VtxoId>) -> Self
Exclude the given vtxos from selection.
Source§impl InputSelection
impl InputSelection
Sourcepub fn new() -> InputSelection
pub fn new() -> InputSelection
Create a new InputSelection with no input limit, no exclusions, and no fee scheme.
Sourcepub fn fee_scheme<F>(
self,
tip: BlockHeight,
calc_fee: F,
) -> InputSelection<FeeScheme<F>>
pub fn fee_scheme<F>( self, tip: BlockHeight, calc_fee: F, ) -> InputSelection<FeeScheme<F>>
Make the selection also cover the fee charged on top of the amount, where the fee itself depends on the selected VTXOs. E.g., a lightning payment, a send-onchain payment.
calc_fee receives the target amount and the VtxoFeeInfo of each selected VTXO
(derived from the tip block height). InputSelection::select then returns the
calculated fee alongside the selected VTXOs.
Sourcepub fn select(
&self,
vtxos: Vec<WalletVtxo>,
amount: Amount,
) -> Result<Vec<WalletVtxo>>
pub fn select( &self, vtxos: Vec<WalletVtxo>, amount: Amount, ) -> Result<Vec<WalletVtxo>>
Select VTXOs from the given candidates to cover the provided amount.
Candidates are selected soonest-expiring-first; see [InputScanner::cover_amount] for how the input limit affects this. The selection is returned soonest-expiring-first.
Returns an error if the amount cannot be reached.
Source§impl<F> InputSelection<FeeScheme<F>>
impl<F> InputSelection<FeeScheme<F>>
Sourcepub fn select(
&self,
vtxos: Vec<WalletVtxo>,
amount: Amount,
) -> Result<(Vec<WalletVtxo>, Amount)>
pub fn select( &self, vtxos: Vec<WalletVtxo>, amount: Amount, ) -> Result<(Vec<WalletVtxo>, Amount)>
Select VTXOs from the given candidates to cover the provided amount plus the fee computed by the configured InputSelection::fee_scheme.
Candidates are selected soonest-expiring-first; see [InputScanner::cover_amount] for how the input limit affects this. The selection is returned soonest-expiring-first.
Returns a collection of VTXOs capable of covering the desired amount as well as the calculated fee.
Trait Implementations§
Source§impl<F: Clone> Clone for InputSelection<F>
impl<F: Clone> Clone for InputSelection<F>
Source§fn clone(&self) -> InputSelection<F>
fn clone(&self) -> InputSelection<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for InputSelection<F>
impl<F: Debug> Debug for InputSelection<F>
Source§impl<F: Default> Default for InputSelection<F>
impl<F: Default> Default for InputSelection<F>
Source§fn default() -> InputSelection<F>
fn default() -> InputSelection<F>
Auto Trait Implementations§
impl<F> Freeze for InputSelection<F>where
F: Freeze,
impl<F> RefUnwindSafe for InputSelection<F>where
F: RefUnwindSafe,
impl<F> Send for InputSelection<F>where
F: Send,
impl<F> Sync for InputSelection<F>where
F: Sync,
impl<F> Unpin for InputSelection<F>where
F: Unpin,
impl<F> UnsafeUnpin for InputSelection<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for InputSelection<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request