penumbra_sdk_dex/
genesis.rs

1use anyhow::Context;
2use penumbra_sdk_proto::{penumbra::core::component::dex::v1 as pb, DomainType};
3use serde::{Deserialize, Serialize};
4
5use crate::DexParameters;
6
7#[derive(Deserialize, Serialize, Debug, Clone)]
8#[serde(try_from = "pb::GenesisContent", into = "pb::GenesisContent")]
9pub struct Content {
10    /// The initial configuration parameters for the DEX component.
11    pub dex_params: DexParameters,
12}
13
14impl From<Content> for pb::GenesisContent {
15    fn from(value: Content) -> Self {
16        pb::GenesisContent {
17            dex_params: Some(value.dex_params.into()),
18        }
19    }
20}
21
22impl TryFrom<pb::GenesisContent> for Content {
23    type Error = anyhow::Error;
24
25    fn try_from(msg: pb::GenesisContent) -> Result<Self, Self::Error> {
26        Ok(Content {
27            dex_params: msg
28                .dex_params
29                .context("dex params not present in protobuf message")?
30                .try_into()?,
31        })
32    }
33}
34
35impl DomainType for Content {
36    type Proto = pb::GenesisContent;
37}
38
39impl Default for Content {
40    fn default() -> Self {
41        Self {
42            dex_params: DexParameters::default(),
43        }
44    }
45}