sui_analytics_indexer/handlers/tables/
package.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::sync::Arc;
5
6use anyhow::Result;
7use async_trait::async_trait;
8use sui_indexer_alt_framework::pipeline::Processor;
9use sui_types::base_types::EpochId;
10use sui_types::full_checkpoint_content::Checkpoint;
11
12use crate::Row;
13use crate::pipeline::Pipeline;
14use crate::tables::MovePackageRow;
15
16pub struct PackageProcessor;
17
18impl Row for MovePackageRow {
19    fn get_epoch(&self) -> EpochId {
20        self.epoch
21    }
22
23    fn get_checkpoint(&self) -> u64 {
24        self.checkpoint
25    }
26}
27
28#[async_trait]
29impl Processor for PackageProcessor {
30    const NAME: &'static str = Pipeline::MovePackage.name();
31    type Value = MovePackageRow;
32
33    async fn process(&self, checkpoint: &Arc<Checkpoint>) -> Result<Vec<Self::Value>> {
34        let epoch = checkpoint.summary.data().epoch;
35        let checkpoint_seq = checkpoint.summary.data().sequence_number;
36        let timestamp_ms = checkpoint.summary.data().timestamp_ms;
37
38        let mut packages = Vec::new();
39
40        for checkpoint_transaction in &checkpoint.transactions {
41            for object in checkpoint_transaction.output_objects(&checkpoint.object_set) {
42                if let sui_types::object::Data::Package(p) = &object.data {
43                    let package_id = p.id();
44                    let package_version = p.version().value();
45                    let original_package_id = p.original_package_id();
46                    let package = MovePackageRow {
47                        package_id: package_id.to_string(),
48                        package_version: Some(package_version),
49                        checkpoint: checkpoint_seq,
50                        epoch,
51                        timestamp_ms,
52                        bcs: "".to_string(),
53                        bcs_length: bcs::to_bytes(object).unwrap().len() as u64,
54                        transaction_digest: object.previous_transaction.to_string(),
55                        original_package_id: Some(original_package_id.to_string()),
56                    };
57                    packages.push(package);
58                }
59            }
60        }
61
62        Ok(packages)
63    }
64}