feat: rotate infura keys for ws

This commit is contained in:
Georgios Konstantopoulos 2022-03-13 10:11:27 -07:00
parent ae125bcfc7
commit 4f37287859
4 changed files with 15 additions and 16 deletions

View File

@ -4,7 +4,7 @@ use ethers_middleware::{
gas_escalator::{Frequency, GasEscalatorMiddleware, GeometricGasPrice}, gas_escalator::{Frequency, GasEscalatorMiddleware, GeometricGasPrice},
signer::SignerMiddleware, signer::SignerMiddleware,
}; };
use ethers_providers::{Middleware, Provider, Ws}; use ethers_providers::Middleware;
use ethers_signers::{LocalWallet, Signer}; use ethers_signers::{LocalWallet, Signer};
use std::time::Duration; use std::time::Duration;
@ -12,10 +12,8 @@ use std::time::Duration;
#[ignore] #[ignore]
async fn gas_escalator_live() { async fn gas_escalator_live() {
// connect to ropsten for getting bad block times // connect to ropsten for getting bad block times
let ws = Ws::connect("wss://ropsten.infura.io/ws/v3/fd8b88b56aa84f6da87b60f5441d6778") let provider = ethers_providers::ROPSTEN.ws().await;
.await let provider = provider.interval(Duration::from_millis(2000u64));
.unwrap();
let provider = Provider::new(ws).interval(Duration::from_millis(2000u64));
let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169" let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"
.parse::<LocalWallet>() .parse::<LocalWallet>()
.unwrap(); .unwrap();

View File

@ -69,11 +69,7 @@ use ethers_core::types::{Address, Eip1559TransactionRequest};
#[tokio::test] #[tokio::test]
#[cfg(not(feature = "celo"))] #[cfg(not(feature = "celo"))]
async fn websocket_pending_txs_with_confirmations_testnet() { async fn websocket_pending_txs_with_confirmations_testnet() {
let provider = let provider = RINKEBY.ws().await.interval(Duration::from_millis(3000));
Provider::connect("wss://rinkeby.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await
.unwrap()
.interval(Duration::from_millis(3000));
let chain_id = provider.get_chainid().await.unwrap(); let chain_id = provider.get_chainid().await.unwrap();
let wallet = WALLETS.next().with_chain_id(chain_id.as_u64()); let wallet = WALLETS.next().with_chain_id(chain_id.as_u64());
let address = wallet.address(); let address = wallet.address();

View File

@ -664,7 +664,7 @@ pub use test_provider::{GOERLI, MAINNET, RINKEBY, ROPSTEN};
/// to prevent rate limits /// to prevent rate limits
pub mod test_provider { pub mod test_provider {
use super::*; use super::*;
use crate::Http; use crate::{Http, Ws};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::{convert::TryFrom, iter::Cycle, slice::Iter, sync::Mutex}; use std::{convert::TryFrom, iter::Cycle, slice::Iter, sync::Mutex};
@ -705,5 +705,14 @@ pub mod test_provider {
); );
Provider::try_from(url.as_str()).unwrap() Provider::try_from(url.as_str()).unwrap()
} }
pub async fn ws(&self) -> Provider<Ws> {
let url = format!(
"wss://{}.infura.io/ws/v3/{}",
self.network,
self.keys.lock().unwrap().next().unwrap()
);
Provider::connect(url.as_str()).await.unwrap()
}
} }
} }

View File

@ -35,11 +35,7 @@ mod eth_tests {
// Without TLS this would error with "TLS Support not compiled in" // Without TLS this would error with "TLS Support not compiled in"
#[tokio::test] #[tokio::test]
async fn ssl_websocket() { async fn ssl_websocket() {
use ethers_providers::Ws; let provider = RINKEBY.ws().await;
let ws = Ws::connect("wss://rinkeby.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await
.unwrap();
let provider = Provider::new(ws);
let _number = provider.get_block_number().await.unwrap(); let _number = provider.get_block_number().await.unwrap();
} }