feat: 添加交易索引功能支持

- 为 TransactionPretty 添加 transaction_index 字段
- 从 Yellowstone gRPC 的 SubscribeUpdateTransaction.transaction.index 提取交易索引
- 为 EventMetadata 添加 transaction_index 字段用于存储交易在 slot 中的索引
- 为 UnifiedEvent trait 添加 transaction_index() 和 set_transaction_index() 方法
- 更新事件处理器以传递交易索引到事件元数据
- 更新主程序日志以显示交易索引信息

交易事件现在包含它们在 slot 中的索引位置,账户事件由于 gRPC 协议限制保持为 None
This commit is contained in:
vnxfsc
2025-08-25 00:37:31 +08:00
parent f87f3dd7f3
commit c3d599acd5
6 changed files with 41 additions and 3 deletions
+8
View File
@@ -63,6 +63,14 @@ macro_rules! impl_unified_event {
fn index(&self) -> String {
self.metadata.index.clone()
}
fn transaction_index(&self) -> Option<u64> {
self.metadata.transaction_index
}
fn set_transaction_index(&mut self, transaction_index: Option<u64>) {
self.metadata.set_transaction_index(transaction_index);
}
}
};
}
+8 -1
View File
@@ -343,6 +343,7 @@ pub struct EventMetadata {
pub id: String,
pub signature: String,
pub slot: u64,
pub transaction_index: Option<u64>, // 新增:交易在slot中的索引
pub block_time: i64,
pub block_time_ms: i64,
pub program_received_time_ms: i64,
@@ -352,7 +353,7 @@ pub struct EventMetadata {
pub program_id: Pubkey,
pub transfer_datas: Vec<TransferData>,
pub swap_data: Option<SwapData>,
pub index: String,
pub index: String, // 保留原有的指令索引
}
impl EventMetadata {
@@ -373,6 +374,7 @@ impl EventMetadata {
id,
signature,
slot,
transaction_index: None, // 默认为None,后续设置
block_time,
block_time_ms,
program_received_time_ms,
@@ -403,6 +405,11 @@ impl EventMetadata {
self.swap_data = swap_data;
}
/// 设置交易索引
pub fn set_transaction_index(&mut self, transaction_index: Option<u64>) {
self.transaction_index = transaction_index;
}
/// Recycle EventMetadata to object pool
pub async fn recycle(self) {
EVENT_METADATA_POOL.release(self).await;