refactor: restructure event handling from trait objects to enum pattern

- Convert UnifiedEvent from trait object (Box<dyn UnifiedEvent>) to concrete enum type
  - Remove match_event! macro in favor of native match expressions
  - Simplify event metadata access: event.event_type() -> event.metadata().event_type
  - Unify event callback signatures: Fn(Box<dyn UnifiedEvent>) -> Fn(UnifiedEvent)
  - Update all example code to use the new enum-based event system
  - Optimize type system to reduce runtime overhead and improve type safety

  Affected scope:
  - Core event parser and processor
  - All protocol event definitions (PumpFun, PumpSwap, Bonk, Raydium series, etc.)
  - gRPC and Shred streaming modules
  - All example code
This commit is contained in:
ysq
2025-10-10 18:19:44 +08:00
parent 77caa39f0c
commit 312a675a40
43 changed files with 1013 additions and 1839 deletions
+1 -35
View File
@@ -3,38 +3,4 @@ pub mod core;
pub mod protocols;
pub use core::traits::UnifiedEvent;
pub use protocols::types::Protocol;
/// 宏:简化 downcast_ref 模式匹配
///
/// # 使用示例
/// ```
/// use sol_trade_sdk::event_parser::match_event;
///
/// match_event!(event, {
/// PumpSwapCreatePoolEvent => |typed_event| {
/// println!("CreatePool event: {:?}", typed_event);
/// },
/// PumpSwapDepositEvent => |typed_event| {
/// // 处理存款事件
/// },
/// });
/// ```
#[macro_export]
macro_rules! match_event {
($event:expr, {
$($event_type:ty => $handler:expr),* $(,)?
}) => {
$(
if let Some(typed_event) = $event.as_any().downcast_ref::<$event_type>() {
$handler(typed_event.clone());
} else
)*
{
// 默认情况:什么都不做
}
};
}
// 重新导出宏以便于使用
pub use match_event;
pub use protocols::types::Protocol;