2020-06-20 13:55:07 +00:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
2022-03-19 17:05:39 +00:00
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(rustdoc::broken_intra_doc_links)]
|
2021-04-05 07:44:58 +00:00
|
|
|
#![allow(clippy::type_complexity)]
|
2021-11-23 19:23:12 +00:00
|
|
|
#![doc = include_str!("../README.md")]
|
2023-02-20 23:55:36 +00:00
|
|
|
#![warn(missing_docs)]
|
2023-01-03 14:15:51 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
mod ext;
|
|
|
|
pub use ext::*;
|
2020-06-10 08:58:27 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
mod rpc;
|
|
|
|
pub use rpc::*;
|
2020-05-26 09:52:15 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
mod toolbox;
|
|
|
|
pub use toolbox::*;
|
2022-11-30 21:22:44 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
/// Crate utilities and type aliases
|
|
|
|
mod utils;
|
|
|
|
pub use utils::{interval, maybe, EscalationPolicy};
|
2020-05-27 11:32:44 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
/// Errors
|
|
|
|
mod errors;
|
|
|
|
pub use errors::{MiddlewareError, ProviderError, RpcError};
|
2022-05-23 21:23:35 +00:00
|
|
|
|
2020-06-15 08:46:07 +00:00
|
|
|
mod stream;
|
|
|
|
pub use futures_util::StreamExt;
|
2022-08-03 16:21:55 +00:00
|
|
|
pub use stream::{
|
2023-02-20 23:55:36 +00:00
|
|
|
tx_stream::TransactionStream, FilterWatcher, DEFAULT_LOCAL_POLL_INTERVAL, DEFAULT_POLL_INTERVAL,
|
2022-08-03 16:21:55 +00:00
|
|
|
};
|
2020-06-15 08:46:07 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
mod middleware;
|
2021-06-15 12:22:53 +00:00
|
|
|
#[cfg(feature = "celo")]
|
2023-02-20 23:55:36 +00:00
|
|
|
pub use middleware::CeloMiddleware;
|
|
|
|
pub use middleware::Middleware;
|
2022-03-13 16:04:09 +00:00
|
|
|
|
2022-12-31 10:47:53 +00:00
|
|
|
#[allow(deprecated)]
|
|
|
|
pub use test_provider::{GOERLI, MAINNET, ROPSTEN, SEPOLIA};
|
2022-03-13 16:04:09 +00:00
|
|
|
|
2023-02-20 23:55:36 +00:00
|
|
|
#[allow(missing_docs)]
|
2022-03-13 16:04:09 +00:00
|
|
|
/// Pre-instantiated Infura HTTP clients which rotate through multiple API keys
|
|
|
|
/// to prevent rate limits
|
|
|
|
pub mod test_provider {
|
|
|
|
use super::*;
|
2022-03-13 18:29:09 +00:00
|
|
|
use crate::Http;
|
2022-03-13 16:04:09 +00:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use std::{convert::TryFrom, iter::Cycle, slice::Iter, sync::Mutex};
|
|
|
|
|
|
|
|
// List of infura keys to rotate through so we don't get rate limited
|
2023-02-02 19:12:15 +00:00
|
|
|
const INFURA_KEYS: &[&str] = &["15e8aaed6f894d63a0f6a0206c006cdd"];
|
2022-03-13 16:04:09 +00:00
|
|
|
|
|
|
|
pub static MAINNET: Lazy<TestProvider> =
|
|
|
|
Lazy::new(|| TestProvider::new(INFURA_KEYS, "mainnet"));
|
2022-12-31 10:47:53 +00:00
|
|
|
pub static GOERLI: Lazy<TestProvider> = Lazy::new(|| TestProvider::new(INFURA_KEYS, "goerli"));
|
|
|
|
pub static SEPOLIA: Lazy<TestProvider> =
|
|
|
|
Lazy::new(|| TestProvider::new(INFURA_KEYS, "sepolia"));
|
|
|
|
|
|
|
|
#[deprecated = "Ropsten testnet has been deprecated in favor of Goerli or Sepolia."]
|
2022-03-13 16:04:09 +00:00
|
|
|
pub static ROPSTEN: Lazy<TestProvider> =
|
|
|
|
Lazy::new(|| TestProvider::new(INFURA_KEYS, "ropsten"));
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TestProvider {
|
|
|
|
network: String,
|
|
|
|
keys: Mutex<Cycle<Iter<'static, &'static str>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestProvider {
|
2022-12-31 10:47:53 +00:00
|
|
|
pub fn new(keys: &'static [&'static str], network: impl Into<String>) -> Self {
|
|
|
|
Self { keys: keys.iter().cycle().into(), network: network.into() }
|
2022-03-13 16:04:09 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 20:40:56 +00:00
|
|
|
pub fn url(&self) -> String {
|
2022-12-31 10:47:53 +00:00
|
|
|
let Self { network, keys } = self;
|
|
|
|
let key = keys.lock().unwrap().next().unwrap();
|
|
|
|
format!("https://{network}.infura.io/v3/{key}")
|
2022-05-18 20:40:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn provider(&self) -> Provider<Http> {
|
|
|
|
Provider::try_from(self.url().as_str()).unwrap()
|
2022-03-13 16:04:09 +00:00
|
|
|
}
|
2022-03-13 17:11:27 +00:00
|
|
|
|
2022-03-13 18:29:09 +00:00
|
|
|
#[cfg(feature = "ws")]
|
|
|
|
pub async fn ws(&self) -> Provider<crate::Ws> {
|
2022-03-13 17:11:27 +00:00
|
|
|
let url = format!(
|
|
|
|
"wss://{}.infura.io/ws/v3/{}",
|
|
|
|
self.network,
|
|
|
|
self.keys.lock().unwrap().next().unwrap()
|
|
|
|
);
|
|
|
|
Provider::connect(url.as_str()).await.unwrap()
|
|
|
|
}
|
2022-03-13 16:04:09 +00:00
|
|
|
}
|
|
|
|
}
|