Struct RefreshStrategy

Source
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>

Source

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_threshold blocks of expiry at tip.

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:

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)?;
Source

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 + 28 blocks) relative to tip.
  • 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:

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<'_>

Source§

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<()>

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,