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
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tendermint::{
abci::responses::{BeginBlock, EndBlock},
Block,
};
use crate::query::EventType;
use crate::{response::Wrapper, Response};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Event {
pub query: String,
pub data: EventData,
pub events: Option<HashMap<String, Vec<String>>>,
}
impl Response for Event {}
pub type WrappedEvent = Wrapper<Event>;
impl Event {
pub fn event_type(&self) -> Option<EventType> {
match self.data {
EventData::NewBlock { .. } => Some(EventType::NewBlock),
EventData::Tx { .. } => Some(EventType::Tx),
_ => None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "type", content = "value")]
pub enum EventData {
#[serde(alias = "tendermint/event/NewBlock")]
NewBlock {
block: Option<Block>,
result_begin_block: Option<BeginBlock>,
result_end_block: Option<EndBlock>,
},
#[serde(alias = "tendermint/event/Tx")]
Tx {
#[serde(rename = "TxResult")]
tx_result: TxInfo,
},
GenericJSONEvent(serde_json::Value),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TxInfo {
pub height: String,
pub index: Option<i64>,
pub tx: String,
pub result: TxResult,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TxResult {
pub log: Option<String>,
pub gas_wanted: Option<String>,
pub gas_used: Option<String>,
pub events: Vec<TmEvent>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TmEvent {
#[serde(rename = "type")]
pub event_type: String,
pub attributes: Vec<Attribute>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Attribute {
pub key: String,
pub value: String,
}