Skip to content

Commit

Permalink
Reuse RPC providers with a time based cached (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah authored Apr 12, 2024
2 parents 6e04525 + 859aa37 commit 366308c
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 63 deletions.
149 changes: 149 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ once_cell = "1.19.0"
rand = "0.8.5"
runit = "0.1.0"
futures-util = "0.3"
mini-moka = "0.10.3"
axum = "0.7.5"
reqwest = "0.12.3"
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "17633df", features = [
Expand Down
15 changes: 5 additions & 10 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use alloy::network::Ethereum;
use std::sync::Arc;

use alloy::rpc::types::eth::{TransactionInput, TransactionRequest};
use alloy_primitives::Bytes;
use alloy_provider::Provider;
use alloy_sol_types::SolCall;
use futures_util::StreamExt;
use tokio::sync::mpsc::Sender;

use crate::chain_list::{ChainListProvider, CHAINS};
use crate::controller::{ControllerCommands, ControllerInterface};
use crate::premints::zora_premint_v2::types::PREMINT_FACTORY_ADDR;
use crate::types::Premint;

pub async fn contract_call<T>(call: T, provider: ChainListProvider) -> eyre::Result<T::Return>
pub async fn contract_call<T>(call: T, provider: Arc<ChainListProvider>) -> eyre::Result<T::Return>
where
T: SolCall,
{
Expand Down Expand Up @@ -89,12 +89,7 @@ impl MintChecker {
}
}

async fn make_provider(&self) -> eyre::Result<ChainListProvider> {
let chain = CHAINS.get_chain_by_id(self.chain_id as i64);

match chain {
Some(c) => c.get_rpc(true).await,
None => Err(eyre::eyre!("Chain not found for id {}", self.chain_id)),
}
async fn make_provider(&self) -> eyre::Result<Arc<ChainListProvider>> {
CHAINS.get_rpc(self.chain_id as i64).await
}
}
Loading

0 comments on commit 366308c

Please sign in to comment.