1use rgbstd::contract::AssignmentsFilter;
23use rgbstd::{Outpoint, Txid};
24
25use crate::WalletProvider;
26
27#[derive(Copy, Clone)]
28pub enum Filter {
29 Outpoints,
30 Unspent,
31 Witness,
32}
33
34pub struct WalletFilter<'wallet, W: WalletProvider + ?Sized> {
35 wallet: &'wallet W,
36 filter: Filter,
37}
38
39impl<'wallet, W: WalletProvider + ?Sized> WalletFilter<'wallet, W> {
40 pub fn new(wallet: &'wallet W, filter: Filter) -> WalletFilter<'wallet, W> {
41 Self { wallet, filter }
42 }
43}
44
45impl<W: WalletProvider + ?Sized> Copy for WalletFilter<'_, W> {}
46impl<W: WalletProvider + ?Sized> Clone for WalletFilter<'_, W> {
47 fn clone(&self) -> Self { *self }
48}
49
50impl<W: WalletProvider + ?Sized> AssignmentsFilter for WalletFilter<'_, W> {
51 fn should_include(&self, outpoint: impl Into<Outpoint>, witness_id: Option<Txid>) -> bool {
52 match self.filter {
53 Filter::Outpoints => self.wallet.has_outpoint(outpoint.into()),
54 Filter::Unspent => self.wallet.is_unspent(outpoint.into()),
55 Filter::Witness => self.wallet.should_include_witness(witness_id),
56 }
57 }
58}