forked from crypto-com/ibc-solo-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.rs
151 lines (143 loc) · 4.86 KB
/
event.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Events generated by solo machine
mod event_handler;
use anyhow::{anyhow, Result};
use primitive_types::U256;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::UnboundedSender;
use crate::{
cosmos::crypto::PublicKey,
ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, Identifier},
model::ConnectionDetails,
};
pub use event_handler::*;
/// Events emitted by IBC service
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
#[allow(clippy::large_enum_variant)]
pub enum Event {
// ----- IBC events ----- //
/// Minted tokens on IBC enabled chain
TokensMinted {
/// Chain ID of IBC enabled chain
chain_id: ChainId,
/// Optional request ID (for tracking purposes)
request_id: Option<String>,
/// Address of account on IBC enabled chain
to_address: String,
/// Amount of tokens minted
amount: U256,
/// Denom of tokens minted
denom: Identifier,
/// Hash of transaction on IBC enabled chain (in hex)
transaction_hash: String,
},
/// Burnt tokens on IBC enabled chain
TokensBurnt {
/// Chain ID of IBC enabled chain
chain_id: ChainId,
/// Optional request ID (for tracking purposes)
request_id: Option<String>,
/// Address of account on IBC enabled chain
from_address: String,
/// Amount of tokens minted
amount: U256,
/// Denom of tokens minted
denom: Identifier,
/// Hash of transaction on IBC enabled chain (in hex)
transaction_hash: String,
},
/// Updated signer's public key on IBC enabled change for future messages from solo machine
SignerUpdated {
/// Chain ID of IBC enabled chain
chain_id: ChainId,
/// Old signer's public key
old_public_key: PublicKey,
/// New signer's public key
new_public_key: PublicKey,
},
// ----- IBC connection handshake events ----- //
/// Created solo machine client on IBC enabled chain
CreatedSoloMachineClient {
/// Client ID of solo machine client on IBC enabled chain
client_id: ClientId,
},
/// Created tendermint client on solo machine
CreatedTendermintClient {
/// Client ID of IBC enabled chain on solo machine
client_id: ClientId,
},
/// Initialized connection on IBC enabled chain
InitializedConnectionOnTendermint {
/// Connection ID of solo machine client on IBC enabled chain
connection_id: ConnectionId,
},
/// Initialized connection on solo machine
InitializedConnectionOnSoloMachine {
/// Connection ID of IBC enabled chain on solo machine
connection_id: ConnectionId,
},
/// Confirmed connection on IBC enabled chain
ConfirmedConnectionOnTendermint {
/// Connection ID of solo machine client on IBC enabled chain
connection_id: ConnectionId,
},
/// Confirmed connection on solo machine
ConfirmedConnectionOnSoloMachine {
/// Connection ID of IBC enabled chain on solo machine
connection_id: ConnectionId,
},
/// Initialized channel on IBC enabled chain
InitializedChannelOnTendermint {
/// Channel ID of solo machine client on IBC enabled chain
channel_id: ChannelId,
},
/// Close channel on IBC enabled chain
CloseChannelInitOnSoloMachine {
/// Chain ID of IBC enabled chain
chain_id: String,
/// Channel ID of IBC enabled chain on solo machine
channel_id: ChannelId,
},
/// Initialized channel on solo machine
InitializedChannelOnSoloMachine {
/// Channel ID of IBC enabled chain on solo machine
channel_id: ChannelId,
},
/// Confirmed channel on IBC enabled chain
ConfirmedChannelOnTendermint {
/// Channel ID of solo machine client on IBC enabled chain
channel_id: ChannelId,
},
/// Confirmed channel on solo machine
ConfirmedChannelOnSoloMachine {
/// Channel ID of IBC enabled chain on solo machine
channel_id: ChannelId,
},
/// Connection successfully established
ConnectionEstablished {
/// Chain ID of IBC enabled chain
chain_id: ChainId,
/// Connection details
connection_details: ConnectionDetails,
},
// ----- Chain events ----- //
/// Added new chain metadata to solo machine
ChainAdded {
/// Chain ID
chain_id: ChainId,
},
// ----- Other events ----- //
/// Warning
Warning {
/// Warning message
message: String,
},
}
pub(crate) fn notify_event(notifier: &Option<UnboundedSender<Event>>, event: Event) -> Result<()> {
match notifier {
None => Ok(()),
Some(ref notifier) => notifier
.send(event)
.map_err(|err| anyhow!("unable to send event to notifier: {}", err)),
}
}