Struct VtxoFilter

Source
pub struct VtxoFilter<'a> {
    pub expires_before: Option<BlockHeight>,
    pub counterparty: bool,
    pub exclude: HashSet<VtxoId>,
    pub include: HashSet<VtxoId>,
    /* private fields */
}
Expand description

Filter vtxos based on criteria.

Builder pattern is used.

Matching semantics:

  • Explicit include and exclude lists have the highest priority.
  • Remaining criteria (expiry, counterparty risk) are combined with OR: if any matches, the VTXO is kept.

Fields§

§expires_before: Option<BlockHeight>

Include vtxos that expire before the given height.

§counterparty: bool

If true, include vtxos that have counterparty risk.

§exclude: HashSet<VtxoId>

Exclude certain vtxos.

§include: HashSet<VtxoId>

Force include certain vtxos.

Implementations§

Source§

impl<'a> VtxoFilter<'a>

Source

pub fn new(wallet: &'a Wallet) -> VtxoFilter<'a>

Create a new VtxoFilter bound to a wallet context.

The wallet is used to evaluate properties such as counterparty risk. By default, the filter matches nothing until criteria are added.

Examples

use bark::vtxo::selection::{VtxoFilter, FilterVtxos};
use bitcoin_ext::BlockHeight;

let tip: BlockHeight = 1_000;
let filter = VtxoFilter::new(wallet)
    .expires_before(tip + 144) // expiring within ~1 day
    .counterparty();           // or with counterparty risk
let filtered = wallet.spendable_vtxos_with(&filter)?;
Source

pub fn expires_before(self, expires_before: BlockHeight) -> Self

Include vtxos that expire before the given height.

Examples

use bark::vtxo::selection::{VtxoFilter, FilterVtxos};
use bitcoin_ext::BlockHeight;

let h: BlockHeight = 10_000;
let filter = VtxoFilter::new(wallet)
    .expires_before(h);
let filtered = wallet.spendable_vtxos_with(&filter)?;
Source

pub fn counterparty(self) -> Self

Include vtxos that have counterparty risk.

An arkoor vtxo is considered to have some counterparty risk if it’s (directly or not) based on round VTXOs that aren’t owned by the wallet.

Source

pub fn exclude(self, exclude: VtxoId) -> Self

Exclude the given vtxo.

Source

pub fn exclude_many(self, exclude: impl IntoIterator<Item = VtxoId>) -> Self

Exclude the given vtxos.

Source

pub fn include(self, include: VtxoId) -> Self

Include the given vtxo.

Source

pub fn include_many(self, include: impl IntoIterator<Item = VtxoId>) -> Self

Include the given vtxos.

Trait Implementations§

Source§

impl FilterVtxos for VtxoFilter<'_>

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 VtxoFilter<'a>

§

impl<'a> !RefUnwindSafe for VtxoFilter<'a>

§

impl<'a> Send for VtxoFilter<'a>

§

impl<'a> Sync for VtxoFilter<'a>

§

impl<'a> Unpin for VtxoFilter<'a>

§

impl<'a> !UnwindSafe for VtxoFilter<'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,