-
Notifications
You must be signed in to change notification settings - Fork 224
/
v0_34.rs
104 lines (89 loc) · 2.56 KB
/
v0_34.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
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
use tendermint::{abci, evidence};
use tendermint_proto::v0_34::types::Evidence as RawEvidence;
use crate::prelude::*;
use crate::serializers::bytes::base64string;
use serde::{Deserialize, Serialize};
#[derive(Default, Clone)]
pub struct Dialect;
impl crate::dialect::Dialect for Dialect {
type Event = Event;
type Evidence = Evidence;
}
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct Event {
#[serde(rename = "type")]
pub kind: String,
pub attributes: Vec<EventAttribute>,
}
impl From<Event> for abci::Event {
fn from(msg: Event) -> Self {
Self {
kind: msg.kind,
attributes: msg.attributes.into_iter().map(Into::into).collect(),
}
}
}
impl From<abci::Event> for Event {
fn from(msg: abci::Event) -> Self {
Self {
kind: msg.kind,
attributes: msg.attributes.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct EventAttribute {
/// The event key.
#[serde(
serialize_with = "base64string::serialize",
deserialize_with = "base64string::deserialize_to_string"
)]
pub key: String,
/// The event value.
#[serde(
serialize_with = "base64string::serialize",
deserialize_with = "base64string::deserialize_to_string"
)]
pub value: String,
/// Whether Tendermint's indexer should index this event.
///
/// **This field is nondeterministic**.
pub index: bool,
}
impl From<EventAttribute> for abci::EventAttribute {
fn from(msg: EventAttribute) -> Self {
Self {
key: msg.key,
value: msg.value,
index: msg.index,
}
}
}
impl From<abci::EventAttribute> for EventAttribute {
fn from(msg: abci::EventAttribute) -> Self {
Self {
key: msg.key,
value: msg.value,
index: msg.index,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(into = "RawEvidence", try_from = "RawEvidence")]
pub struct Evidence(evidence::Evidence);
impl From<Evidence> for RawEvidence {
fn from(evidence: Evidence) -> Self {
evidence.0.into()
}
}
impl TryFrom<RawEvidence> for Evidence {
type Error = <evidence::Evidence as TryFrom<RawEvidence>>::Error;
fn try_from(value: RawEvidence) -> Result<Self, Self::Error> {
Ok(Self(evidence::Evidence::try_from(value)?))
}
}
impl From<evidence::Evidence> for Evidence {
fn from(evidence: evidence::Evidence) -> Self {
Self(evidence)
}
}