-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rpc api ingestion to indexer-alt
- Loading branch information
1 parent
a0b5616
commit dc90055
Showing
9 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
crates/sui-indexer-alt-framework/src/ingestion/rpc_client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::ingestion::client::{FetchError, FetchResult, IngestionClientTrait}; | ||
use anyhow::anyhow; | ||
use bytes::Bytes; | ||
use sui_rpc_api::Client; | ||
use sui_storage::blob::{Blob, BlobEncoding}; | ||
use url::Url; | ||
|
||
pub(crate) struct RpcIngestionClient { | ||
client: Client, | ||
} | ||
|
||
impl RpcIngestionClient { | ||
pub(crate) fn new( | ||
url: Url, | ||
basic_auth: Option<(String, String)>, | ||
) -> Result<Self, anyhow::Error> { | ||
let mut client = Client::new(url.to_string())?; | ||
if let Some(basic_auth) = basic_auth { | ||
client = client.with_basic_auth(basic_auth)?; | ||
} | ||
Ok(Self { client }) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl IngestionClientTrait for RpcIngestionClient { | ||
async fn fetch(&self, checkpoint: u64) -> FetchResult { | ||
let data = self | ||
.client | ||
.get_full_checkpoint(checkpoint) | ||
.await | ||
.map_err(|e| { | ||
if e.message().contains("not found") { | ||
FetchError::NotFound | ||
} else { | ||
FetchError::Transient { | ||
reason: "io_error", | ||
error: anyhow!(e), | ||
} | ||
} | ||
})?; | ||
Ok(Bytes::from( | ||
Blob::encode(&data, BlobEncoding::Bcs)?.to_bytes(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters