Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sozin committed Oct 8, 2024
1 parent caa6ec1 commit 403d924
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 49 deletions.
8 changes: 4 additions & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ serenity = { version = "0.12", features = ["client", "framework"] }
jemallocator = { version = "0.5.0", optional = true }
jemalloc-ctl = { version = "0.5.0", optional = true }

hypersync-client = {path="../../hypersync-client-rust/hypersync-client", features = ["ethers"]}
hypersync-format = {path="../../hypersync-client-rust/hypersync-format", features = ["ethers"]}
hypersync-net-types = {path="../../hypersync-client-rust/hypersync-net-types"}
hypersync-schema = {path="../../hypersync-client-rust/hypersync-schema"}
hypersync-client = {version="0.17.0", features = ["ethers"]}
hypersync-format = {version="0.4.0", features = ["ethers"]}
hypersync-net-types = {version="0.9.0"}
hypersync-schema = {version="0.2.1"}
arrayvec = "0.7.6"

[target.'cfg(not(windows))'.dependencies]
Expand Down
3 changes: 1 addition & 2 deletions core/src/event/contract_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use crate::{
event::callback_registry::Decoder,
generate_random_id,
manifest::contract::{Contract, EventInputIndexedFilters},
provider::{CreateNetworkProvider},
provider::{CreateNetworkProvider, ProviderInterface},
};
use crate::provider::ProviderInterface;

#[derive(Clone)]
pub struct NetworkContract {
Expand Down
2 changes: 1 addition & 1 deletion core/src/indexer/fetch_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use tracing::{debug, error, info, warn};
use crate::{
event::{config::EventProcessingConfig, RindexerEventFilter},
indexer::{log_helpers::is_relevant_block, IndexingEventProgressStatus},
provider::ProviderInterface,
};
use crate::provider::ProviderInterface;

pub struct FetchLogsResult {
pub logs: Vec<Log>,
Expand Down
69 changes: 33 additions & 36 deletions core/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{
any::Any,
collections::BTreeSet,
fmt::Debug,
num::NonZeroU64,
sync::Arc,
time::{Duration, Instant},
};
use std::any::Any;
use std::fmt::Debug;
use async_trait::async_trait;

use arrayvec::ArrayVec;
use async_trait::async_trait;
use ethers::{
middleware::Middleware,
prelude::{Log, ValueOrArray},
Expand Down Expand Up @@ -233,25 +234,21 @@ impl ProviderInterface for HyperSyncProvider {

query.join_mode = JoinMode::JoinNothing;

println!("Query: {:?}", query);
let resp = self
.provider
.clone()
.collect(query, Default::default())
.await
.map_err(|err| ProviderError::CustomError(err.to_string()))?;

println!("time: {}", resp.total_execution_time);
println!("next_block: {}", resp.next_block);
let res = Ok(resp
Ok(resp
.data
.logs
.into_iter()
.flatten()
.filter_map(|log| log.try_into().ok())
.collect::<Vec<Log>>());
.collect::<Vec<Log>>())

res
}

fn max_block_range(&self) -> Option<U64> {
Expand Down Expand Up @@ -287,11 +284,11 @@ pub fn create_client(
})?;
match kind {
ProviderType::Rpc => {
create_jsonrpc_client(url, compute_units_per_second, max_block_range, custom_headers).and_then(|client| Ok(client as Arc<dyn ProviderInterface>))
}
ProviderType::Hypersync => {
create_hypersync_client(url, max_block_range).and_then(|client| Ok(client as Arc<dyn ProviderInterface>))
create_jsonrpc_client(url, compute_units_per_second, max_block_range, custom_headers)
.and_then(|client| Ok(client as Arc<dyn ProviderInterface>))
}
ProviderType::Hypersync => create_hypersync_client(url, max_block_range)
.and_then(|client| Ok(client as Arc<dyn ProviderInterface>)),
}
}

Expand All @@ -301,35 +298,35 @@ pub fn create_jsonrpc_client(
max_block_range: Option<U64>,
custom_headers: HeaderMap,
) -> Result<Arc<JsonRpcCachedProvider>, RetryClientError> {
let client = reqwest::Client::builder().default_headers(custom_headers).build()?;

let provider = Http::new_with_client(url, client);
let instance = Provider::new(
RetryClientBuilder::default()
// assume minimum compute units per second if not provided as growth plan
// standard
.compute_units_per_second(compute_units_per_second.unwrap_or(660))
.rate_limit_retries(5000)
.timeout_retries(1000)
.initial_backoff(Duration::from_millis(500))
.build(provider, Box::<ethers::providers::HttpRateLimitRetryPolicy>::default()),
);
Ok(Arc::new(JsonRpcCachedProvider::new(instance, max_block_range)))
let client = reqwest::Client::builder().default_headers(custom_headers).build()?;

let provider = Http::new_with_client(url, client);
let instance = Provider::new(
RetryClientBuilder::default()
// assume minimum compute units per second if not provided as growth plan
// standard
.compute_units_per_second(compute_units_per_second.unwrap_or(660))
.rate_limit_retries(5000)
.timeout_retries(1000)
.initial_backoff(Duration::from_millis(500))
.build(provider, Box::<ethers::providers::HttpRateLimitRetryPolicy>::default()),
);
Ok(Arc::new(JsonRpcCachedProvider::new(instance, max_block_range)))
}

pub fn create_hypersync_client(
url: Url,
max_block_range: Option<U64>,
) -> Result<Arc<HyperSyncProvider>, RetryClientError> {
let config = ClientConfig {
url: Some(url),
http_req_timeout_millis: NonZeroU64::new(30000),
max_num_retries: 3.into(),
..Default::default()
};
let client = Client::new(config)
.map_err(|err| RetryClientError::CouldNotBuildHypersyncClient(err.to_string()))?;
Ok(Arc::new(HyperSyncProvider::new(client, max_block_range)))
let config = ClientConfig {
url: Some(url),
http_req_timeout_millis: NonZeroU64::new(30000),
max_num_retries: 3.into(),
..Default::default()
};
let client = Client::new(config)
.map_err(|err| RetryClientError::CouldNotBuildHypersyncClient(err.to_string()))?;
Ok(Arc::new(HyperSyncProvider::new(client, max_block_range)))
}

pub async fn get_chain_id(rpc_url: &str) -> Result<U256, ProviderError> {
Expand Down
11 changes: 8 additions & 3 deletions rindexer_rust_playground/src/rindexer_lib/typings/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ fn create_shadow_client(
public_read_env_value("RINDEXER_PHANTOM_API_KEY").unwrap().parse().unwrap(),
);
let url = rpc_url.parse().unwrap();
create_jsonrpc_client(url, compute_units_per_second, max_block_range, header).and_then(|client| Ok(client as Arc<dyn ProviderInterface>))
create_jsonrpc_client(url, compute_units_per_second, max_block_range, header)
.and_then(|client| Ok(client as Arc<dyn ProviderInterface>))
}

lazy_static! {
static ref ETHEREUM_PROVIDER: Arc<JsonRpcCachedProvider> = create_jsonrpc_client(
public_read_env_value("https://mainnet.gateway.tenderly.co")
.unwrap_or("https://mainnet.gateway.tenderly.co".to_string()).parse().unwrap(),
.unwrap_or("https://mainnet.gateway.tenderly.co".to_string())
.parse()
.unwrap(),
None,
None,
HeaderMap::new(),
)
.expect("Error creating provider");
static ref YOMINET_PROVIDER: Arc<JsonRpcCachedProvider> = create_jsonrpc_client(
public_read_env_value("https://yominet.rpc.caldera.xyz/http")
.unwrap_or("https://yominet.rpc.caldera.xyz/http".to_string()).parse().unwrap(),
.unwrap_or("https://yominet.rpc.caldera.xyz/http".to_string())
.parse()
.unwrap(),
None,
Some(U64::from(10000)),
HeaderMap::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rindexer::{
contract::{Contract, ContractDetails},
yaml::read_manifest,
},
provider::{JsonRpcCachedProvider},
provider::JsonRpcCachedProvider,
AsyncCsvAppender, FutureExt, PostgresClient,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rindexer::{
contract::{Contract, ContractDetails},
yaml::read_manifest,
},
provider::{JsonRpcCachedProvider},
provider::JsonRpcCachedProvider,
AsyncCsvAppender, FutureExt, PostgresClient,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rindexer::{
contract::{Contract, ContractDetails},
yaml::read_manifest,
},
provider::{JsonRpcCachedProvider},
provider::JsonRpcCachedProvider,
AsyncCsvAppender, FutureExt, PostgresClient,
};

Expand Down

0 comments on commit 403d924

Please sign in to comment.