use crate::primitives::{AssetName, Lovelace, PolicyId, Quantity};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Value {
pub coin: Lovelace,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub assets: BTreeMap<PolicyId, BTreeMap<AssetName, Quantity>>,
}
impl Value {
pub fn ada(lovelace: u64) -> Self {
Self { coin: Lovelace(lovelace), assets: BTreeMap::new() }
}
pub fn with_asset(mut self, policy: PolicyId, asset: AssetName, qty: u64) -> Self {
self.assets.entry(policy).or_default().insert(asset, Quantity(qty));
self
}
pub fn is_pure_ada(&self) -> bool {
self.assets.is_empty()
}
}