ibc_relayer_types/
proofs.rs1use flex_error::{define_error, TraceError};
2use prost::EncodeError;
3use serde::Serialize;
4
5use crate::core::ics23_commitment::commitment::CommitmentProofBytes;
6use crate::Height;
7
8define_error! {
9 #[derive(Debug, PartialEq, Eq)]
10 ProofError {
11 ZeroHeight
12 | _ | { format_args!("proof height cannot be zero") },
13
14 EmptyProof
15 | _ | { format_args!("proof cannot be empty") },
16
17 Encode
18 [ TraceError<EncodeError> ]
19 | _ | { "protobuf encode error" },
20 }
21}
22
23#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
27pub struct Proofs {
28 object_proof: CommitmentProofBytes,
29 client_proof: Option<CommitmentProofBytes>,
30 consensus_proof: Option<ConsensusProof>,
31 host_consensus_state_proof: Option<CommitmentProofBytes>,
32 other_proof: Option<CommitmentProofBytes>,
34 height: Height,
37}
38
39impl Proofs {
40 pub fn new(
41 object_proof: CommitmentProofBytes,
42 client_proof: Option<CommitmentProofBytes>,
43 consensus_proof: Option<ConsensusProof>,
44 host_consensus_state_proof: Option<CommitmentProofBytes>,
45 other_proof: Option<CommitmentProofBytes>,
46 height: Height,
47 ) -> Result<Self, ProofError> {
48 Ok(Self {
49 object_proof,
50 client_proof,
51 consensus_proof,
52 host_consensus_state_proof,
53 other_proof,
54 height,
55 })
56 }
57
58 pub fn consensus_proof(&self) -> Option<&ConsensusProof> {
61 self.consensus_proof.as_ref()
62 }
63
64 pub fn host_consensus_state_proof(&self) -> Option<&CommitmentProofBytes> {
67 self.host_consensus_state_proof.as_ref()
68 }
69
70 pub fn height(&self) -> Height {
73 self.height
74 }
75
76 pub fn object_proof(&self) -> &CommitmentProofBytes {
78 &self.object_proof
79 }
80
81 pub fn client_proof(&self) -> Option<&CommitmentProofBytes> {
83 self.client_proof.as_ref()
84 }
85
86 pub fn other_proof(&self) -> Option<&CommitmentProofBytes> {
88 self.other_proof.as_ref()
89 }
90}
91
92#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
93pub struct ConsensusProof {
94 proof: CommitmentProofBytes,
95 height: Height,
96}
97
98impl ConsensusProof {
99 pub fn new(
100 consensus_proof: CommitmentProofBytes,
101 consensus_height: Height,
102 ) -> Result<Self, ProofError> {
103 Ok(Self {
104 proof: consensus_proof,
105 height: consensus_height,
106 })
107 }
108
109 pub fn height(&self) -> Height {
111 self.height
112 }
113
114 pub fn proof(&self) -> &CommitmentProofBytes {
116 &self.proof
117 }
118}