penumbra_ibc/
params.rs

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
44
45
46
47
48
49
50
use penumbra_proto::core::component::ibc::v1 as pb;
use penumbra_proto::DomainType;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(try_from = "pb::IbcParameters", into = "pb::IbcParameters")]
pub struct IBCParameters {
    /// Whether IBC (forming connections, processing IBC packets) is enabled.
    pub ibc_enabled: bool,
    /// Whether inbound ICS-20 transfers are enabled
    pub inbound_ics20_transfers_enabled: bool,
    /// Whether outbound ICS-20 transfers are enabled
    pub outbound_ics20_transfers_enabled: bool,
}

impl DomainType for IBCParameters {
    type Proto = pb::IbcParameters;
}

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

    fn try_from(msg: pb::IbcParameters) -> anyhow::Result<Self> {
        Ok(IBCParameters {
            ibc_enabled: msg.ibc_enabled,
            inbound_ics20_transfers_enabled: msg.inbound_ics20_transfers_enabled,
            outbound_ics20_transfers_enabled: msg.outbound_ics20_transfers_enabled,
        })
    }
}

impl From<IBCParameters> for pb::IbcParameters {
    fn from(params: IBCParameters) -> Self {
        pb::IbcParameters {
            ibc_enabled: params.ibc_enabled,
            inbound_ics20_transfers_enabled: params.inbound_ics20_transfers_enabled,
            outbound_ics20_transfers_enabled: params.outbound_ics20_transfers_enabled,
        }
    }
}

impl Default for IBCParameters {
    fn default() -> Self {
        Self {
            ibc_enabled: true,
            inbound_ics20_transfers_enabled: true,
            outbound_ics20_transfers_enabled: true,
        }
    }
}