less anyhow and fix tests
This commit is contained in:
parent
0046a02a4a
commit
efa189d101
@ -60,7 +60,7 @@ pub enum Web3ProxyError {
|
||||
Database(DbErr),
|
||||
DatabaseArc(Arc<DbErr>),
|
||||
Decimal(DecimalError),
|
||||
EthersHttpClient(ethers::prelude::HttpClientError),
|
||||
EthersHttpClient(ethers::providers::HttpClientError),
|
||||
EthersProvider(ethers::prelude::ProviderError),
|
||||
EthersWsClient(ethers::prelude::WsClientError),
|
||||
GasEstimateNotU256,
|
||||
|
@ -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<ethers::providers::Http>;
|
||||
pub type EthersWsProvider = ethers::providers::Provider<ethers::providers::Ws>;
|
||||
|
||||
@ -30,12 +31,14 @@ pub fn connect_http(
|
||||
mut url: Url,
|
||||
http_client: Option<reqwest::Client>,
|
||||
interval: Duration,
|
||||
) -> anyhow::Result<EthersHttpProvider> {
|
||||
) -> Web3ProxyResult<EthersHttpProvider> {
|
||||
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<EthersWsProvider> {
|
||||
pub async fn connect_ws(mut url: Url, reconnects: usize) -> Web3ProxyResult<EthersWsProvider> {
|
||||
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<Ether
|
||||
// TODO: i don't think this interval matters
|
||||
ethers::providers::Provider::new(provider)
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("ws servers are supported"));
|
||||
return Err(anyhow::anyhow!("ws servers are supported").into());
|
||||
};
|
||||
|
||||
Ok(provider)
|
||||
|
@ -47,7 +47,7 @@ pub async fn create_user(
|
||||
.unwrap();
|
||||
trace!(?user_login_response);
|
||||
|
||||
assert_eq!(user_login_response.status(), StatusCode::OK);
|
||||
assert_eq!(user_login_response.status(), StatusCode::CREATED);
|
||||
|
||||
let user_login_text = user_login_response.text().await.unwrap();
|
||||
trace!("user_login_text: {:#}", user_login_text);
|
||||
|
@ -5,6 +5,7 @@ use serde::Deserialize;
|
||||
use tracing::info;
|
||||
use ulid::Ulid;
|
||||
use web3_proxy::{
|
||||
errors::Web3ProxyResult,
|
||||
frontend::users::authentication::LoginPostResponse,
|
||||
rpcs::provider::{connect_http, EthersHttpProvider},
|
||||
};
|
||||
@ -65,7 +66,7 @@ pub async fn user_get_provider(
|
||||
x: &TestApp,
|
||||
r: &reqwest::Client,
|
||||
login_response: &LoginPostResponse,
|
||||
) -> anyhow::Result<EthersHttpProvider> {
|
||||
) -> Web3ProxyResult<EthersHttpProvider> {
|
||||
let first_key = login_response.rpc_keys.iter().next().unwrap().1;
|
||||
|
||||
let rpc_url = format!(
|
||||
|
Loading…
Reference in New Issue
Block a user