mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-16 18:38:05 +00:00
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:
@@ -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
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user