penumbra_sdk_community_pool/
genesis.rs1use anyhow::Context;
2use penumbra_sdk_asset::{Value, STAKING_TOKEN_ASSET_ID};
3use penumbra_sdk_proto::{penumbra::core::component::community_pool::v1 as pb, DomainType};
4use serde::{Deserialize, Serialize};
5
6use crate::params::CommunityPoolParameters;
7
8#[derive(Deserialize, Serialize, Debug, Clone)]
9#[serde(try_from = "pb::GenesisContent", into = "pb::GenesisContent")]
10pub struct Content {
11 pub community_pool_params: CommunityPoolParameters,
13 pub initial_balance: Value,
15}
16
17impl From<Content> for pb::GenesisContent {
18 fn from(genesis: Content) -> Self {
19 pb::GenesisContent {
20 community_pool_params: Some(genesis.community_pool_params.into()),
21 initial_balance: Some(genesis.initial_balance.into()),
22 }
23 }
24}
25
26impl TryFrom<pb::GenesisContent> for Content {
27 type Error = anyhow::Error;
28
29 fn try_from(msg: pb::GenesisContent) -> Result<Self, Self::Error> {
30 Ok(Content {
31 initial_balance: msg
32 .initial_balance
33 .context("Initial balance not present in protobuf message")?
34 .try_into()?,
35 community_pool_params: msg
36 .community_pool_params
37 .context("Community Pool params not present in protobuf message")?
38 .try_into()?,
39 })
40 }
41}
42
43impl DomainType for Content {
44 type Proto = pb::GenesisContent;
45}
46
47impl Default for Content {
48 fn default() -> Self {
49 Content {
50 community_pool_params: CommunityPoolParameters::default(),
51 initial_balance: Value {
52 amount: 0u128.into(),
53 asset_id: *STAKING_TOKEN_ASSET_ID,
54 },
55 }
56 }
57}