penumbra_sdk_ibc/component/
client_counter.rs1use ibc_types::core::client::Height;
2use ibc_types::core::connection::ConnectionId;
3use penumbra_sdk_proto::{penumbra::core::component::ibc::v1 as pb, DomainType};
4
5#[derive(Clone, Debug)]
6pub struct ClientCounter(pub u64);
7
8impl DomainType for ClientCounter {
9 type Proto = pb::ClientCounter;
10}
11
12impl TryFrom<pb::ClientCounter> for ClientCounter {
13 type Error = anyhow::Error;
14
15 fn try_from(p: pb::ClientCounter) -> Result<Self, Self::Error> {
16 Ok(ClientCounter(p.counter))
17 }
18}
19
20impl From<ClientCounter> for pb::ClientCounter {
21 fn from(c: ClientCounter) -> Self {
22 pb::ClientCounter { counter: c.0 }
23 }
24}
25
26#[derive(Clone, Debug)]
27pub struct VerifiedHeights {
28 pub heights: Vec<Height>,
29}
30
31impl DomainType for VerifiedHeights {
32 type Proto = pb::VerifiedHeights;
33}
34
35impl TryFrom<pb::VerifiedHeights> for VerifiedHeights {
36 type Error = anyhow::Error;
37
38 fn try_from(msg: pb::VerifiedHeights) -> Result<Self, Self::Error> {
39 let heights = msg.heights.into_iter().map(TryFrom::try_from).collect();
40 match heights {
41 Ok(heights) => Ok(VerifiedHeights { heights }),
42 Err(e) => anyhow::bail!(format!("invalid height: {e}")),
43 }
44 }
45}
46
47impl From<VerifiedHeights> for pb::VerifiedHeights {
48 fn from(d: VerifiedHeights) -> Self {
49 Self {
50 heights: d.heights.into_iter().map(|h| h.into()).collect(),
51 }
52 }
53}
54
55#[derive(Clone, Debug, Default)]
56pub struct ClientConnections {
57 pub connection_ids: Vec<ConnectionId>,
58}
59
60impl DomainType for ClientConnections {
61 type Proto = pb::ClientConnections;
62}
63
64impl TryFrom<pb::ClientConnections> for ClientConnections {
65 type Error = anyhow::Error;
66
67 fn try_from(msg: pb::ClientConnections) -> Result<Self, Self::Error> {
68 Ok(ClientConnections {
69 connection_ids: msg
70 .connections
71 .into_iter()
72 .map(|h| h.parse())
73 .collect::<Result<Vec<_>, _>>()?,
74 })
75 }
76}
77
78impl From<ClientConnections> for pb::ClientConnections {
79 fn from(d: ClientConnections) -> Self {
80 Self {
81 connections: d
82 .connection_ids
83 .into_iter()
84 .map(|h| h.as_str().to_string())
85 .collect(),
86 }
87 }
88}