1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use penumbra_proto::core::component::community_pool::v1 as pb;
use penumbra_proto::DomainType;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(
    try_from = "pb::CommunityPoolParameters",
    into = "pb::CommunityPoolParameters"
)]
pub struct CommunityPoolParameters {
    /// Whether Community Pool spend proposals are enabled.
    pub community_pool_spend_proposals_enabled: bool,
}

impl DomainType for CommunityPoolParameters {
    type Proto = pb::CommunityPoolParameters;
}

impl TryFrom<pb::CommunityPoolParameters> for CommunityPoolParameters {
    type Error = anyhow::Error;

    fn try_from(msg: pb::CommunityPoolParameters) -> anyhow::Result<Self> {
        Ok(CommunityPoolParameters {
            community_pool_spend_proposals_enabled: msg.community_pool_spend_proposals_enabled,
        })
    }
}

impl From<CommunityPoolParameters> for pb::CommunityPoolParameters {
    fn from(params: CommunityPoolParameters) -> Self {
        pb::CommunityPoolParameters {
            community_pool_spend_proposals_enabled: params.community_pool_spend_proposals_enabled,
        }
    }
}

impl Default for CommunityPoolParameters {
    fn default() -> Self {
        Self {
            community_pool_spend_proposals_enabled: true,
        }
    }
}