penumbra_sdk_shielded_pool/
genesis.rs1use penumbra_sdk_proto::{penumbra::core::component::shielded_pool::v1 as pb, DomainType};
2use serde::{Deserialize, Serialize};
3
4mod allocation;
5
6pub use allocation::Allocation;
7
8use crate::params::ShieldedPoolParameters;
9
10#[derive(Deserialize, Serialize, Debug, Clone)]
11#[serde(try_from = "pb::GenesisContent", into = "pb::GenesisContent")]
12pub struct Content {
13 pub allocations: Vec<Allocation>,
15 pub shielded_pool_params: ShieldedPoolParameters,
17}
18
19impl DomainType for Content {
20 type Proto = pb::GenesisContent;
21}
22
23impl From<Content> for pb::GenesisContent {
24 fn from(value: Content) -> Self {
25 pb::GenesisContent {
26 allocations: value.allocations.into_iter().map(Into::into).collect(),
27 shielded_pool_params: Some(value.shielded_pool_params.into()),
28 }
29 }
30}
31
32impl TryFrom<pb::GenesisContent> for Content {
33 type Error = anyhow::Error;
34
35 fn try_from(msg: pb::GenesisContent) -> Result<Self, Self::Error> {
36 Ok(Content {
37 allocations: msg
38 .allocations
39 .into_iter()
40 .map(TryInto::try_into)
41 .collect::<Result<_, _>>()?,
42 shielded_pool_params: msg
43 .shielded_pool_params
44 .ok_or_else(|| anyhow::anyhow!("proto response missing shielded pool params"))?
45 .try_into()?,
46 })
47 }
48}
49
50impl Default for Content {
51 fn default() -> Self {
52 Self {
53 shielded_pool_params: ShieldedPoolParameters::default(),
54 allocations: vec![
55 Allocation {
56 raw_amount: 1000u128.into(),
57 raw_denom: "penumbra"
58 .parse()
59 .expect("hardcoded \"penumbra\" denom should be parseable"),
60 address: penumbra_sdk_keys::test_keys::ADDRESS_0_STR
61 .parse()
62 .expect("hardcoded test address should be valid"),
63 },
64 Allocation {
65 raw_amount: 100u128.into(),
66 raw_denom: "test_usd"
67 .parse()
68 .expect("hardcoded \"test_usd\" denom should be parseable"),
69 address: penumbra_sdk_keys::test_keys::ADDRESS_0_STR
70 .parse()
71 .expect("hardcoded test address should be valid"),
72 },
73 Allocation {
74 raw_amount: 100u128.into(),
75 raw_denom: "gm"
76 .parse()
77 .expect("hardcoded \"gm\" denom should be parseable"),
78 address: penumbra_sdk_keys::test_keys::ADDRESS_1_STR
79 .parse()
80 .expect("hardcoded test address should be valid"),
81 },
82 Allocation {
83 raw_amount: 100u128.into(),
84 raw_denom: "gn"
85 .parse()
86 .expect("hardcoded \"gn\" denom should be parseable"),
87 address: penumbra_sdk_keys::test_keys::ADDRESS_1_STR
88 .parse()
89 .expect("hardcoded test address should be valid"),
90 },
91 ],
92 }
93 }
94}