Skip to content

Commit

Permalink
fix: proper fantom api urls (gakonst#1170)
Browse files Browse the repository at this point in the history
* fix: proper fantom api urls

* Update ethers-etherscan/Cargo.toml

Co-authored-by: Georgios Konstantopoulos <[email protected]>

* chore: remove dbg

Co-authored-by: Georgios Konstantopoulos <[email protected]>
  • Loading branch information
mattsse and gakonst authored Apr 23, 2022
1 parent f4eb402 commit 2b2ec11
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ethers-etherscan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,34 @@ impl Client {

#[cfg(test)]
mod tests {
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 serial_test::serial;
#[allow(unused)]
fn init_tracing() {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
}

use ethers_core::types::Chain;
use ethers_solc::{Project, ProjectPathsConfig};
#[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();

use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError};
let _abi = client
.contract_abi("0x80AA7cb0006d5DDD91cce684229Ac6e398864606".parse().unwrap())
.await
.unwrap();
})
.await;
}

#[tokio::test]
#[serial]
Expand Down
20 changes: 11 additions & 9 deletions ethers-etherscan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -265,6 +267,7 @@ impl Client {
&self,
form: &Form,
) -> Result<Response<T>> {
trace!(target: "etherscan", "POST FORM {}", self.etherscan_api_url);
Ok(self
.client
.post(self.etherscan_api_url.clone())
Expand All @@ -278,6 +281,7 @@ impl Client {

/// Execute an API GET request with parameters
async fn get_json<T: DeserializeOwned, Q: Serialize>(&self, query: &Q) -> Result<Response<T>> {
trace!(target: "etherscan", "GET JSON {}", self.etherscan_api_url);
let res: ResponseData<T> = self
.client
.get(self.etherscan_api_url.clone())
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2b2ec11

Please sign in to comment.