sui_indexer_alt_framework/ingestion/
rpc_client.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::ingestion::client::{FetchData, FetchError, FetchResult, IngestionClientTrait};
use anyhow::anyhow;
use async_trait::async_trait;
use sui_rpc_api::Client as RpcClient;
use tonic::Code;

#[async_trait]
impl IngestionClientTrait for RpcClient {
    async fn fetch(&self, checkpoint: u64) -> FetchResult {
        let data =
            self.clone()
                .get_full_checkpoint(checkpoint)
                .await
                .map_err(|status| match status.code() {
                    Code::NotFound => FetchError::NotFound,
                    _ => FetchError::Transient {
                        reason: "get_full_checkpoint",
                        error: anyhow!(status),
                    },
                })?;
        Ok(FetchData::CheckpointData(data))
    }
}