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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use serde::Serialize;
use crate::ics23_commitment::commitment::CommitmentProofBytes;
use crate::Height;
use flex_error::define_error;
define_error! {
#[derive(Debug, PartialEq, Eq)]
ProofError {
ZeroHeight
| _ | { format_args!("proof height cannot be zero") },
EmptyProof
| _ | { format_args!("proof cannot be empty") },
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct Proofs {
object_proof: CommitmentProofBytes,
client_proof: Option<CommitmentProofBytes>,
consensus_proof: Option<ConsensusProof>,
other_proof: Option<CommitmentProofBytes>,
height: Height,
}
impl Proofs {
pub fn new(
object_proof: CommitmentProofBytes,
client_proof: Option<CommitmentProofBytes>,
consensus_proof: Option<ConsensusProof>,
other_proof: Option<CommitmentProofBytes>,
height: Height,
) -> Result<Self, ProofError> {
if height.is_zero() {
return Err(ProofError::zero_height());
}
if object_proof.is_empty() {
return Err(ProofError::empty_proof());
}
Ok(Self {
object_proof,
client_proof,
consensus_proof,
other_proof,
height,
})
}
pub fn consensus_proof(&self) -> Option<ConsensusProof> {
self.consensus_proof.clone()
}
pub fn height(&self) -> Height {
self.height
}
pub fn object_proof(&self) -> &CommitmentProofBytes {
&self.object_proof
}
pub fn client_proof(&self) -> &Option<CommitmentProofBytes> {
&self.client_proof
}
pub fn other_proof(&self) -> &Option<CommitmentProofBytes> {
&self.other_proof
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct ConsensusProof {
proof: CommitmentProofBytes,
height: Height,
}
impl ConsensusProof {
pub fn new(
consensus_proof: CommitmentProofBytes,
consensus_height: Height,
) -> Result<Self, ProofError> {
if consensus_height.is_zero() {
return Err(ProofError::zero_height());
}
if consensus_proof.is_empty() {
return Err(ProofError::empty_proof());
}
Ok(Self {
proof: consensus_proof,
height: consensus_height,
})
}
pub fn height(&self) -> Height {
self.height
}
pub fn proof(&self) -> &CommitmentProofBytes {
&self.proof
}
}