From 8b74736b4f04a54e01846b9b5f867e712a960b0a Mon Sep 17 00:00:00 2001 From: optionseskimo <78507171+optionseskimo@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:20:49 +0700 Subject: [PATCH 1/2] feat(chain): add BSC and BSC testnet --- ethers-core/src/types/chain.rs | 6 ++++++ ethers-etherscan/src/lib.rs | 27 ++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 6bcbdd560..49fc1f81b 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -32,6 +32,8 @@ pub enum Chain { Moonriver = 1285, Optimism = 10, OptimismKovan = 69, + BinanceSmartChain = 56, + BinanceSmartChainTestnet = 97, } impl fmt::Display for Chain { @@ -79,6 +81,8 @@ impl TryFrom for Chain { 1285 => Chain::Moonriver, 10 => Chain::Optimism, 69 => Chain::OptimismKovan, + 56 => Chain::BinanceSmartChain, + 97 => Chain::BinanceSmartChainTestnet, _ => return Err(ParseChainError(chain.to_string())), }) } @@ -106,6 +110,8 @@ impl FromStr for Chain { "optimism-kovan" => Chain::OptimismKovan, "fantom" => Chain::Fantom, "fantom-testnet" => Chain::FantomTestnet, + "bsc" => Chain::BinanceSmartChain, + "bsc-testnet" => Chain::BinanceSmartChainTestnet, _ => return Err(ParseChainError(chain.to_owned())), }) } diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 341b855be..68b8fa93f 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -73,6 +73,13 @@ impl Client { Url::parse("https://api-testnet.ftmscan.com"), Url::parse("https://testnet.ftmscan.com"), ), + Chain::BinanceSmartChain => { + (Url::parse("https://api.bscscan.com/api"), Url::parse("https://bscscan.com")) + } + Chain::BinanceSmartChainTestnet => ( + Url::parse("https://api-testnet.bscscan.com/api"), + Url::parse("https://testnet.bscscan.com"), + ), chain => return Err(EtherscanError::ChainNotSupported(chain)), }; @@ -90,15 +97,17 @@ impl Client { let api_key = match chain { Chain::Avalanche | Chain::AvalancheFuji => std::env::var("SNOWTRACE_API_KEY")?, Chain::Polygon | Chain::PolygonMumbai => std::env::var("POLYGONSCAN_API_KEY")?, - Chain::Mainnet | - Chain::Ropsten | - Chain::Kovan | - Chain::Rinkeby | - Chain::Goerli | - Chain::Optimism | - Chain::OptimismKovan | - Chain::Fantom | - Chain::FantomTestnet => std::env::var("ETHERSCAN_API_KEY")?, + Chain::Mainnet + | Chain::Ropsten + | Chain::Kovan + | Chain::Rinkeby + | Chain::Goerli + | Chain::Optimism + | Chain::OptimismKovan + | Chain::Fantom + | Chain::FantomTestnet + | Chain::BinanceSmartChain + | Chain::BinanceSmartChainTestnet => std::env::var("ETHERSCAN_API_KEY")?, Chain::XDai | Chain::Sepolia => String::default(), Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => { From 758fcbaa98115de70a179f50ae5ae36fe091751e Mon Sep 17 00:00:00 2001 From: optionseskimo <78507171+optionseskimo@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:49:57 +0700 Subject: [PATCH 2/2] docs(changelog): add note about new BSC known chains --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f1d6fbb..c162d898b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Unreleased +- Add BSC mainnet and testnet to the list of known chains + [831](https://github.com/gakonst/ethers-rs/pull/831) - Returns error on invalid type conversion instead of panicking [691](https://github.com/gakonst/ethers-rs/pull/691/files) - Change types mapping for solidity `bytes` to rust `ethers::core::Bytes` and