sui_indexer_alt_framework/ingestion/
rpc_client.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use anyhow::anyhow;
5use async_trait::async_trait;
6use prost_types::FieldMask;
7use sui_rpc::Client as RpcClient;
8use sui_rpc::field::FieldMaskUtil;
9use sui_rpc::proto::sui::rpc::v2::GetCheckpointRequest;
10use sui_types::full_checkpoint_content::Checkpoint;
11use tonic::Code;
12
13use crate::ingestion::ingestion_client::{
14    FetchData, FetchError, FetchResult, IngestionClientTrait,
15};
16
17#[async_trait]
18impl IngestionClientTrait for RpcClient {
19    async fn fetch(&self, checkpoint: u64) -> FetchResult {
20        let request: GetCheckpointRequest = GetCheckpointRequest::by_sequence_number(checkpoint)
21            .with_read_mask(FieldMask::from_paths([
22                "summary.bcs",
23                "signature",
24                "contents.bcs",
25                "transactions.transaction.bcs",
26                "transactions.effects.bcs",
27                "transactions.effects.unchanged_loaded_runtime_objects",
28                "transactions.events.bcs",
29                "objects.objects.bcs",
30            ]));
31
32        let response = self
33            .clone()
34            .ledger_client()
35            .get_checkpoint(request)
36            .await
37            .map_err(|status| match status.code() {
38                Code::NotFound => FetchError::NotFound,
39                _ => FetchError::Transient {
40                    reason: "get_checkpoint",
41                    error: anyhow!(status),
42                },
43            })?
44            .into_inner();
45
46        let checkpoint =
47            Checkpoint::try_from(response.checkpoint()).map_err(|e| FetchError::Permanent {
48                reason: "proto_conversion",
49                error: e.into(),
50            })?;
51
52        Ok(FetchData::Checkpoint(checkpoint))
53    }
54}