sui_analytics_indexer/handlers/
move_call_handler.rs1use std::sync::Arc;
5
6use anyhow::Result;
7
8use sui_types::full_checkpoint_content::CheckpointData;
9use sui_types::transaction::TransactionDataAPI;
10
11use crate::FileType;
12use crate::handlers::{AnalyticsHandler, TransactionProcessor, process_transactions};
13use crate::tables::MoveCallEntry;
14
15const NAME: &str = "move_call";
16
17#[derive(Clone)]
18pub struct MoveCallHandler {}
19
20impl MoveCallHandler {
21 pub fn new() -> Self {
22 Self {}
23 }
24}
25
26#[async_trait::async_trait]
27impl AnalyticsHandler<MoveCallEntry> for MoveCallHandler {
28 async fn process_checkpoint(
29 &self,
30 checkpoint_data: &Arc<CheckpointData>,
31 ) -> Result<Box<dyn Iterator<Item = MoveCallEntry> + Send + Sync>> {
32 process_transactions(checkpoint_data.clone(), Arc::new(self.clone())).await
33 }
34
35 fn file_type(&self) -> Result<FileType> {
36 Ok(FileType::MoveCall)
37 }
38
39 fn name(&self) -> &'static str {
40 NAME
41 }
42}
43
44#[async_trait::async_trait]
45impl TransactionProcessor<MoveCallEntry> for MoveCallHandler {
46 async fn process_transaction(
47 &self,
48 tx_idx: usize,
49 checkpoint: &CheckpointData,
50 ) -> Result<Box<dyn Iterator<Item = MoveCallEntry> + Send + Sync>> {
51 let transaction = &checkpoint.transactions[tx_idx];
52 let move_calls = transaction.transaction.transaction_data().move_calls();
53 let epoch = checkpoint.checkpoint_summary.epoch;
54 let checkpoint_seq = checkpoint.checkpoint_summary.sequence_number;
55 let timestamp_ms = checkpoint.checkpoint_summary.timestamp_ms;
56 let transaction_digest = transaction.transaction.digest().base58_encode();
57
58 let mut entries = Vec::new();
59 for (package, module, function) in move_calls.iter() {
60 let entry = MoveCallEntry {
61 transaction_digest: transaction_digest.clone(),
62 checkpoint: checkpoint_seq,
63 epoch,
64 timestamp_ms,
65 package: package.to_string(),
66 module: module.to_string(),
67 function: function.to_string(),
68 };
69 entries.push(entry);
70 }
71
72 Ok(Box::new(entries.into_iter()))
73 }
74}