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
use dyn_clone::DynClone;
use crate::dynamic_typing::AsAny;
use crate::prelude::*;
use crate::core::ics24_host::identifier::ClientId;
use crate::Height;
pub trait Misbehaviour:
AsAny + sealed::ErasedPartialEqMisbehaviour + DynClone + core::fmt::Debug + Send + Sync
{
fn client_id(&self) -> &ClientId;
fn height(&self) -> Height;
}
dyn_clone::clone_trait_object!(Misbehaviour);
impl PartialEq for dyn Misbehaviour {
fn eq(&self, other: &Self) -> bool {
self.eq_misbehaviour(other)
}
}
mod sealed {
use super::*;
pub trait ErasedPartialEqMisbehaviour {
fn eq_misbehaviour(&self, other: &dyn Misbehaviour) -> bool;
}
impl<H> ErasedPartialEqMisbehaviour for H
where
H: Misbehaviour + PartialEq,
{
fn eq_misbehaviour(&self, other: &dyn Misbehaviour) -> bool {
other
.as_any()
.downcast_ref::<H>()
.map_or(false, |h| self == h)
}
}
}