feat(etherscan): additional chain apis (#1343)
* xdai * sokol * poa & rsk * oasis chains * fix test * test
This commit is contained in:
parent
030488eca5
commit
f4712fa47c
|
@ -44,6 +44,12 @@ pub enum Chain {
|
||||||
BinanceSmartChain = 56,
|
BinanceSmartChain = 56,
|
||||||
#[strum(serialize = "bsc-testnet")]
|
#[strum(serialize = "bsc-testnet")]
|
||||||
BinanceSmartChainTestnet = 97,
|
BinanceSmartChainTestnet = 97,
|
||||||
|
Poa = 99,
|
||||||
|
Sokol = 77,
|
||||||
|
Rsk = 30,
|
||||||
|
Oasis = 26863,
|
||||||
|
Emerald = 42262,
|
||||||
|
EmeraldTestnet = 42261,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Chain {
|
impl fmt::Display for Chain {
|
||||||
|
@ -74,6 +80,12 @@ impl fmt::Display for Chain {
|
||||||
Chain::ArbitrumTestnet => "arbitrum-testnet",
|
Chain::ArbitrumTestnet => "arbitrum-testnet",
|
||||||
Chain::Cronos => "cronos",
|
Chain::Cronos => "cronos",
|
||||||
Chain::CronosTestnet => "cronos-testnet",
|
Chain::CronosTestnet => "cronos-testnet",
|
||||||
|
Chain::Poa => "poa",
|
||||||
|
Chain::Sokol => "sokol",
|
||||||
|
Chain::Rsk => "rsk",
|
||||||
|
Chain::Oasis => "oasis",
|
||||||
|
Chain::Emerald => "emerald",
|
||||||
|
Chain::EmeraldTestnet => "emerald-testnet",
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(formatter, "{}", chain)
|
write!(formatter, "{}", chain)
|
||||||
|
@ -128,6 +140,12 @@ impl TryFrom<u64> for Chain {
|
||||||
421611 => Chain::ArbitrumTestnet,
|
421611 => Chain::ArbitrumTestnet,
|
||||||
25 => Chain::Cronos,
|
25 => Chain::Cronos,
|
||||||
338 => Chain::CronosTestnet,
|
338 => Chain::CronosTestnet,
|
||||||
|
99 => Chain::Poa,
|
||||||
|
77 => Chain::Sokol,
|
||||||
|
30 => Chain::Rsk,
|
||||||
|
26863 => Chain::Oasis,
|
||||||
|
42262 => Chain::Emerald,
|
||||||
|
42261 => Chain::EmeraldTestnet,
|
||||||
_ => return Err(ParseChainError(chain.to_string())),
|
_ => return Err(ParseChainError(chain.to_string())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -173,6 +191,12 @@ impl FromStr for Chain {
|
||||||
"arbitrum-testnet" => Chain::ArbitrumTestnet,
|
"arbitrum-testnet" => Chain::ArbitrumTestnet,
|
||||||
"cronos" => Chain::Cronos,
|
"cronos" => Chain::Cronos,
|
||||||
"cronos-testnet" => Chain::CronosTestnet,
|
"cronos-testnet" => Chain::CronosTestnet,
|
||||||
|
"poa" => Chain::Poa,
|
||||||
|
"sokol" => Chain::Sokol,
|
||||||
|
"rsk" => Chain::Rsk,
|
||||||
|
"oasis" => Chain::Oasis,
|
||||||
|
"emerald" => Chain::Emerald,
|
||||||
|
"emerald-testnet" => Chain::EmeraldTestnet,
|
||||||
_ => return Err(ParseChainError(chain.to_owned())),
|
_ => return Err(ParseChainError(chain.to_owned())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -192,7 +216,11 @@ impl Chain {
|
||||||
Chain::BinanceSmartChain |
|
Chain::BinanceSmartChain |
|
||||||
Chain::BinanceSmartChainTestnet |
|
Chain::BinanceSmartChainTestnet |
|
||||||
Chain::Arbitrum |
|
Chain::Arbitrum |
|
||||||
Chain::ArbitrumTestnet,
|
Chain::ArbitrumTestnet |
|
||||||
|
Chain::Rsk |
|
||||||
|
Chain::Oasis |
|
||||||
|
Chain::Emerald |
|
||||||
|
Chain::EmeraldTestnet,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,14 @@ impl Client {
|
||||||
Chain::Fantom | Chain::FantomTestnet => {
|
Chain::Fantom | Chain::FantomTestnet => {
|
||||||
std::env::var("FTMSCAN_API_KEY").or_else(|_| std::env::var("FANTOMSCAN_API_KEY"))?
|
std::env::var("FTMSCAN_API_KEY").or_else(|_| std::env::var("FANTOMSCAN_API_KEY"))?
|
||||||
}
|
}
|
||||||
|
Chain::XDai |
|
||||||
Chain::XDai | Chain::Sepolia => String::default(),
|
Chain::Sepolia |
|
||||||
|
Chain::Rsk |
|
||||||
|
Chain::Sokol |
|
||||||
|
Chain::Poa |
|
||||||
|
Chain::Oasis |
|
||||||
|
Chain::Emerald |
|
||||||
|
Chain::EmeraldTestnet => 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")?
|
||||||
}
|
}
|
||||||
|
@ -268,6 +274,29 @@ impl ClientBuilder {
|
||||||
Chain::Moonriver => {
|
Chain::Moonriver => {
|
||||||
urls("https://api-moonriver.moonscan.io/api", "https://moonriver.moonscan.io")
|
urls("https://api-moonriver.moonscan.io/api", "https://moonriver.moonscan.io")
|
||||||
}
|
}
|
||||||
|
// blockscout API is etherscan compatible
|
||||||
|
Chain::XDai => urls(
|
||||||
|
"https://blockscout.com/xdai/mainnet/api",
|
||||||
|
"https://blockscout.com/xdai/mainnet",
|
||||||
|
),
|
||||||
|
Chain::Sokol => {
|
||||||
|
urls("https://blockscout.com/poa/sokol/api", "https://blockscout.com/poa/sokol")
|
||||||
|
}
|
||||||
|
Chain::Poa => {
|
||||||
|
urls("https://blockscout.com/poa/core/api", "https://blockscout.com/poa/core")
|
||||||
|
}
|
||||||
|
Chain::Rsk => {
|
||||||
|
urls("https://blockscout.com/rsk/mainnet/api", "https://blockscout.com/rsk/mainnet")
|
||||||
|
}
|
||||||
|
Chain::Oasis => urls("https://scan.oasischain.io/api", "https://scan.oasischain.io/"),
|
||||||
|
Chain::Emerald => urls(
|
||||||
|
"https://explorer.emerald.oasis.dev/api",
|
||||||
|
"https://explorer.emerald.oasis.dev/",
|
||||||
|
),
|
||||||
|
Chain::EmeraldTestnet => urls(
|
||||||
|
"https://testnet.explorer.emerald.oasis.dev/api",
|
||||||
|
"https://testnet.explorer.emerald.oasis.dev/",
|
||||||
|
),
|
||||||
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
|
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
|
||||||
chain => return Err(EtherscanError::ChainNotSupported(chain)),
|
chain => return Err(EtherscanError::ChainNotSupported(chain)),
|
||||||
};
|
};
|
||||||
|
@ -447,10 +476,10 @@ mod tests {
|
||||||
|
|
||||||
#[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::Sepolia).unwrap_err();
|
||||||
|
|
||||||
assert!(matches!(err, EtherscanError::ChainNotSupported(_)));
|
assert!(matches!(err, EtherscanError::ChainNotSupported(_)));
|
||||||
assert_eq!(err.to_string(), "Chain xdai not supported");
|
assert_eq!(err.to_string(), "Chain sepolia not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue