use zebra_chain::{
amount::{Amount, NonNegative},
value_balance::ValueBalance,
};
use super::*;
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ValuePoolBalance {
id: String,
chain_value: Zec<NonNegative>,
chain_value_zat: Amount<NonNegative>,
}
impl ValuePoolBalance {
pub fn zero_pools() -> [Self; 5] {
Self::from_value_balance(Default::default())
}
pub fn new(id: impl ToString, amount: Amount<NonNegative>) -> Self {
Self {
id: id.to_string(),
chain_value: Zec::from(amount),
chain_value_zat: amount,
}
}
pub fn transparent(amount: Amount<NonNegative>) -> Self {
Self::new("transparent", amount)
}
pub fn sprout(amount: Amount<NonNegative>) -> Self {
Self::new("sprout", amount)
}
pub fn sapling(amount: Amount<NonNegative>) -> Self {
Self::new("sapling", amount)
}
pub fn orchard(amount: Amount<NonNegative>) -> Self {
Self::new("orchard", amount)
}
pub fn deferred(amount: Amount<NonNegative>) -> Self {
Self::new("deferred", amount)
}
pub fn from_value_balance(value_balance: ValueBalance<NonNegative>) -> [Self; 5] {
[
Self::transparent(value_balance.transparent_amount()),
Self::sprout(value_balance.sprout_amount()),
Self::sapling(value_balance.sapling_amount()),
Self::orchard(value_balance.orchard_amount()),
Self::deferred(value_balance.deferred_amount()),
]
}
}