From 2b2ec1101a3e76c66ed23af422b5b5f67461f0d6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 23 Apr 2022 10:42:12 +0200 Subject: [PATCH] fix: proper fantom api urls (#1170) * fix: proper fantom api urls * Update ethers-etherscan/Cargo.toml Co-authored-by: Georgios Konstantopoulos * chore: remove dbg Co-authored-by: Georgios Konstantopoulos --- Cargo.lock | 2 ++ ethers-etherscan/Cargo.toml | 2 ++ ethers-etherscan/src/contract.rs | 30 +++++++++++++++++++++++++----- ethers-etherscan/src/lib.rs | 20 +++++++++++--------- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 042edee8..34500ddb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1277,6 +1277,8 @@ dependencies = [ "tempfile", "thiserror", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/ethers-etherscan/Cargo.toml b/ethers-etherscan/Cargo.toml index 354ff64b..2d9e7985 100644 --- a/ethers-etherscan/Cargo.toml +++ b/ethers-etherscan/Cargo.toml @@ -21,11 +21,13 @@ serde = { version = "1.0.124", default-features = false, features = ["derive"] } serde_json = { version = "1.0.64", default-features = false } serde-aux = { version = "3.0.1", default-features = false } thiserror = "1.0.29" +tracing = "0.1.34" [dev-dependencies] tempfile = "3.3.0" tokio = { version = "1.5", features = ["macros", "rt-multi-thread", "time"] } serial_test = "0.6.0" +tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] } [package.metadata.docs.rs] all-features = true diff --git a/ethers-etherscan/src/contract.rs b/ethers-etherscan/src/contract.rs index 7ccb5d42..a2d497d9 100644 --- a/ethers-etherscan/src/contract.rs +++ b/ethers-etherscan/src/contract.rs @@ -364,14 +364,34 @@ impl Client { #[cfg(test)] mod tests { - use std::{path::PathBuf, time::Duration}; - - use serial_test::serial; - + use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError}; use ethers_core::types::Chain; use ethers_solc::{Project, ProjectPathsConfig}; + use serial_test::serial; + use std::{path::PathBuf, time::Duration}; - use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError}; + #[allow(unused)] + fn init_tracing() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); + } + + #[tokio::test] + #[serial] + #[ignore] + async fn can_fetch_ftm_contract_abi() { + init_tracing(); + run_at_least_duration(Duration::from_millis(250), async { + let client = Client::new_from_env(Chain::Fantom).unwrap(); + + let _abi = client + .contract_abi("0x80AA7cb0006d5DDD91cce684229Ac6e398864606".parse().unwrap()) + .await + .unwrap(); + }) + .await; + } #[tokio::test] #[serial] diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 2a6213eb..e5b6f1a1 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -10,6 +10,7 @@ use std::{ use contract::ContractMetadata; use reqwest::{header, Url}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use tracing::trace; use errors::EtherscanError; use ethers_core::{ @@ -166,10 +167,10 @@ impl Client { Url::parse("https://kovan-optimistic.etherscan.io"), ), Chain::Fantom => { - (Url::parse("https://api.ftmscan.com"), Url::parse("https://ftmscan.com")) + (Url::parse("https://api.ftmscan.com/api"), Url::parse("https://ftmscan.com")) } Chain::FantomTestnet => ( - Url::parse("https://api-testnet.ftmscan.com"), + Url::parse("https://api-testnet.ftmscan.com/api"), Url::parse("https://testnet.ftmscan.com"), ), Chain::BinanceSmartChain => { @@ -215,19 +216,20 @@ impl Client { Chain::Goerli | Chain::Optimism | Chain::OptimismKovan | - Chain::Fantom | - Chain::FantomTestnet | Chain::BinanceSmartChain | Chain::BinanceSmartChainTestnet | Chain::Arbitrum | Chain::ArbitrumTestnet | Chain::Cronos => std::env::var("ETHERSCAN_API_KEY")?, + Chain::Fantom | Chain::FantomTestnet => { + std::env::var("FTMSCAN_API_KEY").or_else(|_| std::env::var("FANTOMSCAN_API_KEY"))? + } Chain::XDai | Chain::Sepolia | Chain::CronosTestnet => String::default(), Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => { std::env::var("MOONSCAN_API_KEY")? } - Chain::Dev => return Err(errors::EtherscanError::LocalNetworksNotSupported), + Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported), }; Self::new(chain, api_key) } @@ -265,6 +267,7 @@ impl Client { &self, form: &Form, ) -> Result> { + trace!(target: "etherscan", "POST FORM {}", self.etherscan_api_url); Ok(self .client .post(self.etherscan_api_url.clone()) @@ -278,6 +281,7 @@ impl Client { /// Execute an API GET request with parameters async fn get_json(&self, query: &Q) -> Result> { + trace!(target: "etherscan", "GET JSON {}", self.etherscan_api_url); let res: ResponseData = self .client .get(self.etherscan_api_url.clone()) @@ -342,15 +346,13 @@ struct Query<'a, T: Serialize> { #[cfg(test)] mod tests { + use crate::{Client, EtherscanError}; + use ethers_core::types::{Address, Chain, H256}; use std::{ future::Future, time::{Duration, SystemTime}, }; - use ethers_core::types::{Address, Chain, H256}; - - use crate::{Client, EtherscanError}; - #[test] fn chain_not_supported() { let err = Client::new_from_env(Chain::XDai).unwrap_err();