From efa189d1016397e8487900b7b06a9d5248f4d190 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 14 Jul 2023 18:31:00 -0700 Subject: [PATCH] less anyhow and fix tests --- web3_proxy/src/errors.rs | 2 +- web3_proxy/src/rpcs/provider.rs | 18 +++++++++--------- web3_proxy/tests/common/create_user.rs | 2 +- web3_proxy/tests/common/rpc_key.rs | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/web3_proxy/src/errors.rs b/web3_proxy/src/errors.rs index bc577d65..659172ea 100644 --- a/web3_proxy/src/errors.rs +++ b/web3_proxy/src/errors.rs @@ -60,7 +60,7 @@ pub enum Web3ProxyError { Database(DbErr), DatabaseArc(Arc), Decimal(DecimalError), - EthersHttpClient(ethers::prelude::HttpClientError), + EthersHttpClient(ethers::providers::HttpClientError), EthersProvider(ethers::prelude::ProviderError), EthersWsClient(ethers::prelude::WsClientError), GasEstimateNotU256, diff --git a/web3_proxy/src/rpcs/provider.rs b/web3_proxy/src/rpcs/provider.rs index 45c82147..2e53e267 100644 --- a/web3_proxy/src/rpcs/provider.rs +++ b/web3_proxy/src/rpcs/provider.rs @@ -2,7 +2,8 @@ use ethers::providers::{Authorization, ConnectionDetails}; use std::time::Duration; use url::Url; -// TODO: our own structs for these that handle streaming large responses +use crate::errors::Web3ProxyResult; + pub type EthersHttpProvider = ethers::providers::Provider; pub type EthersWsProvider = ethers::providers::Provider; @@ -30,12 +31,14 @@ pub fn connect_http( mut url: Url, http_client: Option, interval: Duration, -) -> anyhow::Result { +) -> Web3ProxyResult { let auth = extract_auth(&mut url); let mut provider = if url.scheme().starts_with("http") { let provider = if let Some(auth) = auth { - ethers::providers::Http::new_with_auth(url, auth)? + // TODO: there are two "HttpClientError" in ethers. this one is not in the prelude + ethers::providers::Http::new_with_auth(url, auth) + .map_err(|err| anyhow::anyhow!("http client error: {:?}", err))? } else if let Some(http_client) = http_client { ethers::providers::Http::new_with_client(url, http_client) } else { @@ -45,10 +48,7 @@ pub fn connect_http( // TODO: i don't think this interval matters for our uses, but we should probably set it to like `block time / 2` ethers::providers::Provider::new(provider).interval(Duration::from_secs(2)) } else { - return Err(anyhow::anyhow!( - "only http servers are supported. cannot use {}", - url - )); + return Err(anyhow::anyhow!("only http servers are supported. cannot use {}", url).into()); }; provider.set_interval(interval); @@ -56,7 +56,7 @@ pub fn connect_http( Ok(provider) } -pub async fn connect_ws(mut url: Url, reconnects: usize) -> anyhow::Result { +pub async fn connect_ws(mut url: Url, reconnects: usize) -> Web3ProxyResult { let auth = extract_auth(&mut url); let provider = if url.scheme().starts_with("ws") { @@ -73,7 +73,7 @@ pub async fn connect_ws(mut url: Url, reconnects: usize) -> anyhow::Result anyhow::Result { +) -> Web3ProxyResult { let first_key = login_response.rpc_keys.iter().next().unwrap().1; let rpc_url = format!(