feat(chain): add BSC and BSC testnet (#831)

* feat(chain): add BSC and BSC testnet

* docs(changelog): add note about new BSC known chains
This commit is contained in:
Options Eskimo 2022-01-27 14:50:11 +00:00 committed by GitHub
parent a97526d6fe
commit f434e0f57f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View File

@ -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

View File

@ -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<u64> 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())),
})
}

View File

@ -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 => {