pub struct RefreshStrategy<'a> { /* private fields */ }Expand description
Strategy to select VTXOs that need proactive refreshing.
Refreshing is recommended when a VTXO is nearing its expiry, has reached a soft/hard out-of-round depth threshold, or is uneconomical to exit onchain at the current fee rate.
Variants:
- RefreshStrategy::must_refresh: strict selection intended for mandatory refresh actions (e.g., at or beyond maximum depth or near-hard expiry threshold).
- RefreshStrategy::should_refresh: softer selection for opportunistic refreshes (e.g., approaching soft thresholds or uneconomical unilateral exit).
This type implements FilterVtxos, so it can be passed directly to
Wallet::vtxos_with or [Wallet::inround_vtxos_with].
Implementations§
Source§impl<'a> RefreshStrategy<'a>
impl<'a> RefreshStrategy<'a>
Sourcepub fn must_refresh(
wallet: &'a Wallet,
tip: BlockHeight,
fee_rate: FeeRate,
) -> Self
pub fn must_refresh( wallet: &'a Wallet, tip: BlockHeight, fee_rate: FeeRate, ) -> Self
Builds a strategy that matches VTXOs that must be refreshed immediately.
A WalletVtxo is selected when at least one of the following strict conditions holds:
- It reached or exceeded the maximum allowed out-of-round (OOR) depth (if configured by the Ark server info in the wallet).
- It is within
vtxo_refresh_expiry_thresholdblocks of expiry attip.
Parameters:
wallet: Wallet context used to read configuration and Ark parameters.tip: Current chain tip height used to evaluate expiry proximity.fee_rate: FeeRate to use for any economic checks (kept for parity with the “should” strategy; not all checks require it in the strict mode).
Returns:
- A RefreshStrategy implementing FilterVtxos. Pass it to Wallet::vtxos_with or call FilterVtxos::filter_vtxos directly.
Examples
use bark::vtxo::selection::{FilterVtxos, RefreshStrategy};
use bitcoin::FeeRate;
use bitcoin_ext::BlockHeight;
let tip: BlockHeight = 200_000;
let fr = FeeRate::from_sat_per_vb(5).unwrap();
let must = RefreshStrategy::must_refresh(wallet, tip, fr);
must.filter_vtxos(&mut vtxos)?;Sourcepub fn should_refresh(
wallet: &'a Wallet,
tip: BlockHeight,
fee_rate: FeeRate,
) -> Self
pub fn should_refresh( wallet: &'a Wallet, tip: BlockHeight, fee_rate: FeeRate, ) -> Self
Builds a strategy that matches VTXOs that should be refreshed soon (opportunistic).
A WalletVtxo is selected when at least one of the following softer conditions holds:
- It is at or beyond a soft OOR depth threshold (typically one less than the maximum, if configured by the Ark server info in the wallet).
- It is within a softer expiry window (e.g.,
vtxo_refresh_expiry_threshold + 28blocks) relative totip. - It is uneconomical to unilaterally exit at the provided
fee_rate(e.g., its amount is lower than the estimated exit cost).
Parameters:
wallet: Wallet context used to read configuration and Ark parameters.tip: Current chain tip height used to evaluate expiry proximity.fee_rate: FeeRate used for economic feasibility checks.
Returns:
- A RefreshStrategy implementing FilterVtxos. Pass it to Wallet::vtxos_with or call FilterVtxos::filter_vtxos directly.
Examples
use bark::vtxo::selection::{FilterVtxos, RefreshStrategy};
use bitcoin::FeeRate;
use bitcoin_ext::BlockHeight;
let tip: BlockHeight = 200_000;
let fr = FeeRate::from_sat_per_vb(8).unwrap();
let should = RefreshStrategy::should_refresh(wallet, tip, fr);
should.filter_vtxos(&mut vtxos)?;Trait Implementations§
Source§impl FilterVtxos for RefreshStrategy<'_>
impl FilterVtxos for RefreshStrategy<'_>
Source§fn matches(&self, vtxo: &WalletVtxo) -> Result<bool>
fn matches(&self, vtxo: &WalletVtxo) -> Result<bool>
Check whether the VTXO mathes this filter
Source§fn filter_vtxos<V: Borrow<WalletVtxo>>(&self, vtxos: &mut Vec<V>) -> Result<()>
fn filter_vtxos<V: Borrow<WalletVtxo>>(&self, vtxos: &mut Vec<V>) -> Result<()>
Eliminate from the vector all non-matching VTXOs
Auto Trait Implementations§
impl<'a> Freeze for RefreshStrategy<'a>
impl<'a> !RefUnwindSafe for RefreshStrategy<'a>
impl<'a> Send for RefreshStrategy<'a>
impl<'a> Sync for RefreshStrategy<'a>
impl<'a> Unpin for RefreshStrategy<'a>
impl<'a> !UnwindSafe for RefreshStrategy<'a>
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
Mutably borrows from an owned value. Read more
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>
Wrap the input message
T in a tonic::Request