use zcash_protocol::{PoolType, ShieldedProtocol};
#[derive(Clone, Copy)]
pub struct OutputSpendStatusQuery {
pub unspent: bool,
pub pending_spent: bool,
pub spent: bool,
}
impl OutputSpendStatusQuery {
pub fn any() -> Self {
Self {
unspent: true,
pending_spent: true,
spent: true,
}
}
pub fn only_unspent() -> Self {
Self {
unspent: true,
pending_spent: false,
spent: false,
}
}
pub fn only_pending_spent() -> Self {
Self {
unspent: false,
pending_spent: true,
spent: false,
}
}
pub fn only_spent() -> Self {
Self {
unspent: false,
pending_spent: false,
spent: true,
}
}
pub fn spentish() -> Self {
Self {
unspent: false,
pending_spent: true,
spent: true,
}
}
}
#[derive(Clone, Copy)]
pub struct OutputPoolQuery {
pub transparent: bool,
pub sapling: bool,
pub orchard: bool,
}
impl OutputPoolQuery {
pub fn any() -> Self {
Self {
transparent: true,
sapling: true,
orchard: true,
}
}
pub fn shielded() -> Self {
Self {
transparent: false,
sapling: true,
orchard: true,
}
}
pub fn one_pool(pool_type: PoolType) -> Self {
match pool_type {
PoolType::Transparent => Self {
transparent: true,
sapling: false,
orchard: false,
},
PoolType::Shielded(ShieldedProtocol::Sapling) => Self {
transparent: false,
sapling: true,
orchard: false,
},
PoolType::Shielded(ShieldedProtocol::Orchard) => Self {
transparent: false,
sapling: false,
orchard: true,
},
}
}
}
#[derive(Clone, Copy)]
pub struct OutputQuery {
pub spend_status: OutputSpendStatusQuery,
pub pools: OutputPoolQuery,
}
impl OutputQuery {
pub fn any() -> Self {
Self {
spend_status: OutputSpendStatusQuery::any(),
pools: OutputPoolQuery::any(),
}
}
pub fn only_unspent() -> Self {
Self {
spend_status: OutputSpendStatusQuery {
unspent: true,
pending_spent: false,
spent: false,
},
pools: OutputPoolQuery::any(),
}
}
pub fn stipulations(
unspent: bool,
pending_spent: bool,
spent: bool,
transparent: bool,
sapling: bool,
orchard: bool,
) -> Self {
Self {
spend_status: OutputSpendStatusQuery {
unspent,
pending_spent,
spent,
},
pools: OutputPoolQuery {
transparent,
sapling,
orchard,
},
}
}
pub fn unspent(&self) -> bool {
self.spend_status.unspent
}
pub fn pending_spent(&self) -> bool {
self.spend_status.pending_spent
}
pub fn spent(&self) -> bool {
self.spend_status.spent
}
pub fn transparent(&self) -> bool {
self.pools.transparent
}
pub fn sapling(&self) -> bool {
self.pools.sapling
}
pub fn orchard(&self) -> bool {
self.pools.orchard
}
}