[draft] Add Optimism & OptimismKovan chains (#737)

* core: Add Optimism & OptimismKovan chains

* etherscan: Add ETHERSCAN_API_KEY to optimism network
This commit is contained in:
bayu ✦ 2021-12-25 23:19:50 +07:00 committed by GitHub
parent 47e188793b
commit 3f095f415f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -18,6 +18,8 @@ pub enum Chain {
Moonbeam, Moonbeam,
MoonbeamDev, MoonbeamDev,
Moonriver, Moonriver,
Optimism,
OptimismKovan,
} }
impl fmt::Display for Chain { impl fmt::Display for Chain {
@ -43,6 +45,8 @@ impl From<Chain> for u32 {
Chain::Moonbeam => 1287, Chain::Moonbeam => 1287,
Chain::MoonbeamDev => 1281, Chain::MoonbeamDev => 1281,
Chain::Moonriver => 1285, Chain::Moonriver => 1285,
Chain::Optimism => 10,
Chain::OptimismKovan => 69,
} }
} }
} }

View File

@ -58,6 +58,14 @@ impl Client {
Url::parse("https://api-testnet.snowtrace.io/api"), Url::parse("https://api-testnet.snowtrace.io/api"),
Url::parse("https://testnet.snowtrace.io"), Url::parse("https://testnet.snowtrace.io"),
), ),
Chain::Optimism => (
Url::parse("https://api-optimistic.etherscan.io/api"),
Url::parse("https://optimistic.etherscan.io"),
),
Chain::OptimismKovan => (
Url::parse("https://api-kovan-optimistic.etherscan.io/api"),
Url::parse("https://kovan-optimistic.etherscan.io"),
),
chain => return Err(EtherscanError::ChainNotSupported(chain)), chain => return Err(EtherscanError::ChainNotSupported(chain)),
}; };
@ -75,9 +83,13 @@ impl Client {
let api_key = match chain { let api_key = match chain {
Chain::Avalanche | Chain::AvalancheFuji => std::env::var("SNOWTRACE_API_KEY")?, Chain::Avalanche | Chain::AvalancheFuji => std::env::var("SNOWTRACE_API_KEY")?,
Chain::Polygon | Chain::PolygonMumbai => std::env::var("POLYGONSCAN_API_KEY")?, Chain::Polygon | Chain::PolygonMumbai => std::env::var("POLYGONSCAN_API_KEY")?,
Chain::Mainnet | Chain::Ropsten | Chain::Kovan | Chain::Rinkeby | Chain::Goerli => { Chain::Mainnet
std::env::var("ETHERSCAN_API_KEY")? | Chain::Ropsten
} | Chain::Kovan
| Chain::Rinkeby
| Chain::Goerli
| Chain::Optimism
| Chain::OptimismKovan => std::env::var("ETHERSCAN_API_KEY")?,
Chain::XDai | Chain::Sepolia => String::default(), Chain::XDai | Chain::Sepolia => String::default(),
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => { Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {