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
+6 -1
View File
@@ -90,7 +90,7 @@ impl EventProcessor {
// 使用缓存获取解析器
let parser = self.get_or_create_parser(protocols.clone(), event_type_filter);
let all_events = parser
let mut all_events = parser
.parse_transaction(
transaction_pretty.tx.clone(),
&signature,
@@ -105,6 +105,11 @@ impl EventProcessor {
.await
.unwrap_or_else(|_e| vec![]);
// 为所有事件设置交易索引
for event in &mut all_events {
event.set_transaction_index(transaction_pretty.transaction_index);
}
// 保存事件数量用于日志记录
let event_count = all_events.len();
+5
View File
@@ -66,6 +66,7 @@ impl fmt::Debug for BlockMetaPretty {
#[derive(Clone)]
pub struct TransactionPretty {
pub slot: u64,
pub transaction_index: Option<u64>, // 新增:交易在slot中的索引
pub block_hash: String,
pub block_time: Option<Timestamp>,
pub signature: Signature,
@@ -85,6 +86,7 @@ impl fmt::Debug for TransactionPretty {
f.debug_struct("TransactionPretty")
.field("slot", &self.slot)
.field("transaction_index", &self.transaction_index)
.field("signature", &self.signature)
.field("is_vote", &self.is_vote)
.field("tx", &TxWrap(&self.tx))
@@ -127,8 +129,11 @@ impl From<(SubscribeUpdateTransaction, Option<Timestamp>)> for TransactionPretty
),
) -> Self {
let tx = transaction.expect("should be defined");
// 根据用户说明,交易索引在 transaction.index 中
let transaction_index = tx.index;
Self {
slot,
transaction_index: Some(transaction_index), // 提取交易索引
block_time,
block_hash: "".to_string(),
signature: Signature::try_from(tx.signature.as_slice()).expect("valid signature"),