penumbra_sdk_asset/
equivalent_value.rs1use crate::asset::Metadata;
2use penumbra_sdk_num::Amount;
3use penumbra_sdk_proto::{penumbra::core::asset::v1 as pb, DomainType};
4use serde::{Deserialize, Serialize};
5
6#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
10#[serde(try_from = "pb::EquivalentValue", into = "pb::EquivalentValue")]
11pub struct EquivalentValue {
12 pub equivalent_amount: Amount,
14 pub numeraire: Metadata,
16 pub as_of_height: u64,
18}
19
20impl DomainType for EquivalentValue {
21 type Proto = pb::EquivalentValue;
22}
23
24impl From<EquivalentValue> for pb::EquivalentValue {
25 fn from(v: EquivalentValue) -> Self {
26 pb::EquivalentValue {
27 equivalent_amount: Some(v.equivalent_amount.into()),
28 numeraire: Some(v.numeraire.into()),
29 as_of_height: v.as_of_height,
30 }
31 }
32}
33
34impl TryFrom<pb::EquivalentValue> for EquivalentValue {
35 type Error = anyhow::Error;
36 fn try_from(value: pb::EquivalentValue) -> Result<Self, Self::Error> {
37 Ok(EquivalentValue {
38 equivalent_amount: value
39 .equivalent_amount
40 .ok_or_else(|| anyhow::anyhow!("missing equivalent_amount field"))?
41 .try_into()?,
42 numeraire: value
43 .numeraire
44 .ok_or_else(|| anyhow::anyhow!("missing numeraire field"))?
45 .try_into()?,
46 as_of_height: value.as_of_height,
47 })
48 }
49}