2025-09-14 01:13:11 +08:00
|
|
|
use crate::streaming::event_parser::common::EventType;
|
|
|
|
|
use crate::streaming::event_parser::common::SwapData;
|
2025-08-26 17:57:39 +08:00
|
|
|
use solana_sdk::signature::Signature;
|
2025-07-19 23:46:42 +08:00
|
|
|
use std::fmt::Debug;
|
2025-08-31 22:18:18 +08:00
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Unified Event Interface - All protocol events must implement this trait
|
2025-07-19 23:46:42 +08:00
|
|
|
pub trait UnifiedEvent: Debug + Send + Sync {
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Get event type
|
2025-07-19 23:46:42 +08:00
|
|
|
fn event_type(&self) -> EventType;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Get transaction signature
|
2025-09-02 17:27:27 +08:00
|
|
|
fn signature(&self) -> &Signature;
|
2025-07-19 23:46:42 +08:00
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Get slot number
|
2025-07-19 23:46:42 +08:00
|
|
|
fn slot(&self) -> u64;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Get program received timestamp (milliseconds)
|
2025-09-03 15:49:50 +08:00
|
|
|
fn recv_us(&self) -> i64;
|
2025-07-19 23:46:42 +08:00
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Processing time consumption (milliseconds)
|
2025-09-03 15:49:50 +08:00
|
|
|
fn handle_us(&self) -> i64;
|
2025-07-29 14:48:43 +08:00
|
|
|
|
|
|
|
|
/// Set processing time consumption (milliseconds)
|
2025-09-03 15:49:50 +08:00
|
|
|
fn set_handle_us(&mut self, handle_us: i64);
|
2025-07-29 14:48:43 +08:00
|
|
|
|
|
|
|
|
/// Convert event to Any for downcasting
|
2025-07-19 23:46:42 +08:00
|
|
|
fn as_any(&self) -> &dyn std::any::Any;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Convert event to mutable Any for downcasting
|
2025-07-19 23:46:42 +08:00
|
|
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Clone the event
|
2025-07-19 23:46:42 +08:00
|
|
|
fn clone_boxed(&self) -> Box<dyn UnifiedEvent>;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Merge events (optional implementation)
|
2025-08-27 21:31:31 +08:00
|
|
|
fn merge(&mut self, _other: &dyn UnifiedEvent) {
|
2025-07-29 14:48:43 +08:00
|
|
|
// Default implementation: no merging operation
|
2025-07-19 23:46:42 +08:00
|
|
|
}
|
2025-07-21 23:55:13 +08:00
|
|
|
|
2025-08-26 17:57:39 +08:00
|
|
|
/// Set swap data
|
|
|
|
|
fn set_swap_data(&mut self, swap_data: SwapData);
|
2025-07-26 17:11:28 +08:00
|
|
|
|
2025-08-31 22:18:18 +08:00
|
|
|
/// swap_data is parsed
|
|
|
|
|
fn swap_data_is_parsed(&self) -> bool;
|
|
|
|
|
|
2025-07-29 14:48:43 +08:00
|
|
|
/// Get index
|
2025-09-03 15:49:50 +08:00
|
|
|
fn outer_index(&self) -> i64;
|
|
|
|
|
fn inner_index(&self) -> Option<i64>;
|
2025-08-25 00:37:31 +08:00
|
|
|
|
|
|
|
|
/// Get transaction index in slot
|
|
|
|
|
fn transaction_index(&self) -> Option<u64>;
|
2025-07-19 23:46:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 为Box<dyn UnifiedEvent>实现Clone
|
|
|
|
|
impl Clone for Box<dyn UnifiedEvent> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
self.clone_boxed()
|
|
|
|
|
}
|
|
|
|
|
}
|