penumbra_asset/
estimated_price.rsuse crate::asset;
use penumbra_proto::{penumbra::core::asset::v1 as pb, DomainType};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
#[serde(try_from = "pb::EstimatedPrice", into = "pb::EstimatedPrice")]
pub struct EstimatedPrice {
pub priced_asset: asset::Id,
pub numeraire: asset::Id,
pub numeraire_per_unit: f64,
pub as_of_height: u64,
}
impl DomainType for EstimatedPrice {
type Proto = pb::EstimatedPrice;
}
impl From<EstimatedPrice> for pb::EstimatedPrice {
fn from(msg: EstimatedPrice) -> Self {
Self {
priced_asset: Some(msg.priced_asset.into()),
numeraire: Some(msg.numeraire.into()),
numeraire_per_unit: msg.numeraire_per_unit,
as_of_height: msg.as_of_height,
}
}
}
impl TryFrom<pb::EstimatedPrice> for EstimatedPrice {
type Error = anyhow::Error;
fn try_from(msg: pb::EstimatedPrice) -> Result<Self, Self::Error> {
Ok(Self {
priced_asset: msg
.priced_asset
.ok_or_else(|| anyhow::anyhow!("missing priced asset"))?
.try_into()?,
numeraire: msg
.numeraire
.ok_or_else(|| anyhow::anyhow!("missing numeraire"))?
.try_into()?,
numeraire_per_unit: msg.numeraire_per_unit,
as_of_height: msg.as_of_height,
})
}
}