penumbra_asset/
equivalent_value.rsuse crate::asset::Metadata;
use penumbra_num::Amount;
use penumbra_proto::{penumbra::core::asset::v1 as pb, DomainType};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
#[serde(try_from = "pb::EquivalentValue", into = "pb::EquivalentValue")]
pub struct EquivalentValue {
pub equivalent_amount: Amount,
pub numeraire: Metadata,
pub as_of_height: u64,
}
impl DomainType for EquivalentValue {
type Proto = pb::EquivalentValue;
}
impl From<EquivalentValue> for pb::EquivalentValue {
fn from(v: EquivalentValue) -> Self {
pb::EquivalentValue {
equivalent_amount: Some(v.equivalent_amount.into()),
numeraire: Some(v.numeraire.into()),
as_of_height: v.as_of_height,
}
}
}
impl TryFrom<pb::EquivalentValue> for EquivalentValue {
type Error = anyhow::Error;
fn try_from(value: pb::EquivalentValue) -> Result<Self, Self::Error> {
Ok(EquivalentValue {
equivalent_amount: value
.equivalent_amount
.ok_or_else(|| anyhow::anyhow!("missing equivalent_amount field"))?
.try_into()?,
numeraire: value
.numeraire
.ok_or_else(|| anyhow::anyhow!("missing numeraire field"))?
.try_into()?,
as_of_height: value.as_of_height,
})
}
}