feat: Add block metadata event support

- Implement BlockMetaEvent and SDKSystemEventParser
- Support block metadata subscription and processing
- Optimize event handling with separate tokio tasks
- Add commitment parameter support
- Upgrade version to 0.1.3
This commit is contained in:
ysq
2025-07-24 19:37:34 +08:00
parent a5269bb1ff
commit a4987b9a3e
8 changed files with 143 additions and 35 deletions
@@ -18,6 +18,7 @@ pub enum ProtocolType {
Bonk,
RaydiumCpmm,
RaydiumClmm,
SDKSystem,
}
/// 事件类型枚举
@@ -54,6 +55,7 @@ pub enum EventType {
RaydiumClmmSwapV2,
// 通用事件
SDKSystem,
Unknown,
}
@@ -77,6 +79,7 @@ impl EventType {
EventType::RaydiumCpmmSwapBaseOutput => "RaydiumCpmmSwapBaseOutput".to_string(),
EventType::RaydiumClmmSwap => "RaydiumClmmSwap".to_string(),
EventType::RaydiumClmmSwapV2 => "RaydiumClmmSwapV2".to_string(),
EventType::SDKSystem => "SDKSystem".to_string(),
EventType::Unknown => "Unknown".to_string(),
}
}
+39
View File
@@ -1,4 +1,6 @@
use anyhow::Result;
use borsh::BorshDeserialize;
use serde::{Deserialize, Serialize};
use solana_sdk::{
instruction::CompiledInstruction, pubkey::Pubkey, transaction::VersionedTransaction,
};
@@ -7,7 +9,9 @@ use solana_transaction_status::{
};
use std::fmt::Debug;
use std::{collections::HashMap, str::FromStr};
use yellowstone_grpc_proto::geyser::SubscribeUpdateBlockMeta;
use crate::impl_unified_event;
use crate::streaming::event_parser::common::{
parse_transfer_datas_from_next_instructions, TransferData,
};
@@ -53,6 +57,18 @@ pub trait UnifiedEvent: Debug + Send + Sync {
fn set_transfer_datas(&mut self, transfer_datas: Vec<TransferData>);
}
/// block meta 事件
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
pub struct BlockMetaEvent {
pub metadata: EventMetadata,
pub slot: u64,
pub blockhash: String,
pub block_time: i64,
}
// 使用宏生成UnifiedEvent实现,指定需要合并的字段
impl_unified_event!(BlockMetaEvent,);
/// 事件解析器trait - 定义了事件解析的核心方法
#[async_trait::async_trait]
pub trait EventParser: Send + Sync {
@@ -534,3 +550,26 @@ impl EventParser for GenericEventParser {
vec![self.program_id]
}
}
pub struct SDKSystemEventParser {}
impl SDKSystemEventParser {
pub fn parse_block(block: SubscribeUpdateBlockMeta) -> Box<dyn UnifiedEvent> {
Box::new(BlockMetaEvent {
metadata: EventMetadata::new(
block.blockhash.to_string(),
"".to_string(),
block.slot,
ProtocolType::SDKSystem,
EventType::SDKSystem,
Pubkey::default(),
),
slot: block.slot,
blockhash: block.blockhash.to_string(),
block_time: if let Some(block_time) = block.block_time {
block_time.timestamp
} else {
0
},
})
}
}