fix: proper fantom api urls (#1170)
* fix: proper fantom api urls * Update ethers-etherscan/Cargo.toml Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> * chore: remove dbg Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
parent
f4eb4029b4
commit
2b2ec1101a
|
@ -1277,6 +1277,8 @@ dependencies = [
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -21,11 +21,13 @@ serde = { version = "1.0.124", default-features = false, features = ["derive"] }
|
||||||
serde_json = { version = "1.0.64", default-features = false }
|
serde_json = { version = "1.0.64", default-features = false }
|
||||||
serde-aux = { version = "3.0.1", default-features = false }
|
serde-aux = { version = "3.0.1", default-features = false }
|
||||||
thiserror = "1.0.29"
|
thiserror = "1.0.29"
|
||||||
|
tracing = "0.1.34"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
tokio = { version = "1.5", features = ["macros", "rt-multi-thread", "time"] }
|
tokio = { version = "1.5", features = ["macros", "rt-multi-thread", "time"] }
|
||||||
serial_test = "0.6.0"
|
serial_test = "0.6.0"
|
||||||
|
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
|
@ -364,14 +364,34 @@ impl Client {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{path::PathBuf, time::Duration};
|
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError};
|
||||||
|
|
||||||
use serial_test::serial;
|
|
||||||
|
|
||||||
use ethers_core::types::Chain;
|
use ethers_core::types::Chain;
|
||||||
use ethers_solc::{Project, ProjectPathsConfig};
|
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]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::{
|
||||||
use contract::ContractMetadata;
|
use contract::ContractMetadata;
|
||||||
use reqwest::{header, Url};
|
use reqwest::{header, Url};
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
use errors::EtherscanError;
|
use errors::EtherscanError;
|
||||||
use ethers_core::{
|
use ethers_core::{
|
||||||
|
@ -166,10 +167,10 @@ impl Client {
|
||||||
Url::parse("https://kovan-optimistic.etherscan.io"),
|
Url::parse("https://kovan-optimistic.etherscan.io"),
|
||||||
),
|
),
|
||||||
Chain::Fantom => {
|
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 => (
|
Chain::FantomTestnet => (
|
||||||
Url::parse("https://api-testnet.ftmscan.com"),
|
Url::parse("https://api-testnet.ftmscan.com/api"),
|
||||||
Url::parse("https://testnet.ftmscan.com"),
|
Url::parse("https://testnet.ftmscan.com"),
|
||||||
),
|
),
|
||||||
Chain::BinanceSmartChain => {
|
Chain::BinanceSmartChain => {
|
||||||
|
@ -215,19 +216,20 @@ impl Client {
|
||||||
Chain::Goerli |
|
Chain::Goerli |
|
||||||
Chain::Optimism |
|
Chain::Optimism |
|
||||||
Chain::OptimismKovan |
|
Chain::OptimismKovan |
|
||||||
Chain::Fantom |
|
|
||||||
Chain::FantomTestnet |
|
|
||||||
Chain::BinanceSmartChain |
|
Chain::BinanceSmartChain |
|
||||||
Chain::BinanceSmartChainTestnet |
|
Chain::BinanceSmartChainTestnet |
|
||||||
Chain::Arbitrum |
|
Chain::Arbitrum |
|
||||||
Chain::ArbitrumTestnet |
|
Chain::ArbitrumTestnet |
|
||||||
Chain::Cronos => std::env::var("ETHERSCAN_API_KEY")?,
|
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::XDai | Chain::Sepolia | Chain::CronosTestnet => String::default(),
|
||||||
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
|
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
|
||||||
std::env::var("MOONSCAN_API_KEY")?
|
std::env::var("MOONSCAN_API_KEY")?
|
||||||
}
|
}
|
||||||
Chain::Dev => return Err(errors::EtherscanError::LocalNetworksNotSupported),
|
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
|
||||||
};
|
};
|
||||||
Self::new(chain, api_key)
|
Self::new(chain, api_key)
|
||||||
}
|
}
|
||||||
|
@ -265,6 +267,7 @@ impl Client {
|
||||||
&self,
|
&self,
|
||||||
form: &Form,
|
form: &Form,
|
||||||
) -> Result<Response<T>> {
|
) -> Result<Response<T>> {
|
||||||
|
trace!(target: "etherscan", "POST FORM {}", self.etherscan_api_url);
|
||||||
Ok(self
|
Ok(self
|
||||||
.client
|
.client
|
||||||
.post(self.etherscan_api_url.clone())
|
.post(self.etherscan_api_url.clone())
|
||||||
|
@ -278,6 +281,7 @@ impl Client {
|
||||||
|
|
||||||
/// Execute an API GET request with parameters
|
/// Execute an API GET request with parameters
|
||||||
async fn get_json<T: DeserializeOwned, Q: Serialize>(&self, query: &Q) -> Result<Response<T>> {
|
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
|
let res: ResponseData<T> = self
|
||||||
.client
|
.client
|
||||||
.get(self.etherscan_api_url.clone())
|
.get(self.etherscan_api_url.clone())
|
||||||
|
@ -342,15 +346,13 @@ struct Query<'a, T: Serialize> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::{Client, EtherscanError};
|
||||||
|
use ethers_core::types::{Address, Chain, H256};
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ethers_core::types::{Address, Chain, H256};
|
|
||||||
|
|
||||||
use crate::{Client, EtherscanError};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_not_supported() {
|
fn chain_not_supported() {
|
||||||
let err = Client::new_from_env(Chain::XDai).unwrap_err();
|
let err = Client::new_from_env(Chain::XDai).unwrap_err();
|
||||||
|
|
Loading…
Reference in New Issue