mina_node_testing/node/rust/
event.rs1use node::{
2 p2p::{webrtc::ConnectionAuthEncrypted, P2pConnectionEvent, P2pEvent, PeerId},
3 rpc::{RpcId, RpcRequest},
4};
5use serde::{Deserialize, Serialize};
6
7pub use node::event_source::Event;
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub enum NonDeterministicEvent {
11 P2pConnectionFinalized(PeerId, Result<ConnectionAuthEncrypted, String>),
14 P2pConnectionClosed(PeerId),
15
16 RpcReadonly(RpcId, Box<RpcRequest>),
17}
18
19impl NonDeterministicEvent {
20 pub fn new(event: &Event) -> Option<Box<Self>> {
21 Some(match event {
22 Event::P2p(e) => match e {
23 P2pEvent::Connection(e) => match e {
24 P2pConnectionEvent::Finalized(id, res) => {
25 Self::P2pConnectionFinalized(*id, res.clone()).into()
26 }
27 P2pConnectionEvent::Closed(id) => Self::P2pConnectionClosed(*id).into(),
28 _ => return None,
29 },
30 P2pEvent::Channel(_) => return None,
31 #[cfg(feature = "p2p-libp2p")]
32 P2pEvent::MioEvent(_) => return None,
33 },
34 Event::Rpc(id, req) => match req.as_ref() {
35 RpcRequest::P2pConnectionIncoming(_) => return None,
36 req => Self::RpcReadonly(*id, Box::new(req.clone())).into(),
37 },
38 _ => return None,
39 })
40 }
41
42 pub fn should_drop_event(event: &Event) -> bool {
43 Self::new(event).is_some_and(|e| e.should_drop())
44 }
45
46 pub fn should_drop(&self) -> bool {
47 false
49 }
50}