feat(ethers-core/Chain): make to_string and from_str inverse functions (#903)
This commit is contained in:
parent
d4eb78730a
commit
1f0eb725a7
|
@ -4,6 +4,7 @@
|
|||
|
||||
### Unreleased
|
||||
|
||||
- `Chain::to_string` will return the same chain name as `Chain::from_str`
|
||||
- Add `eth_syncing` [848](https://github.com/gakonst/ethers-rs/pull/848)
|
||||
- Fix overflow and possible divide-by-zero in `estimate_priority_fee`
|
||||
- Add BSC mainnet and testnet to the list of known chains
|
||||
|
|
|
@ -40,7 +40,32 @@ pub enum Chain {
|
|||
|
||||
impl fmt::Display for Chain {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "{:?}", self)
|
||||
let chain = match self {
|
||||
Chain::Mainnet => "mainnet",
|
||||
Chain::Ropsten => "ropsten",
|
||||
Chain::Rinkeby => "rinkeby",
|
||||
Chain::Goerli => "goerli",
|
||||
Chain::Kovan => "kovan",
|
||||
Chain::XDai => "xdai",
|
||||
Chain::Polygon => "polygon",
|
||||
Chain::PolygonMumbai => "polygon-mumbai",
|
||||
Chain::Avalanche => "avalanche",
|
||||
Chain::AvalancheFuji => "avalanche-fuji",
|
||||
Chain::Sepolia => "sepolia",
|
||||
Chain::Moonbeam => "moonbeam",
|
||||
Chain::MoonbeamDev => "moonbeam-dev",
|
||||
Chain::Moonriver => "moonriver",
|
||||
Chain::Optimism => "optimism",
|
||||
Chain::OptimismKovan => "optimism-kovan",
|
||||
Chain::Fantom => "fantom",
|
||||
Chain::FantomTestnet => "fantom-testnet",
|
||||
Chain::BinanceSmartChain => "bsc",
|
||||
Chain::BinanceSmartChainTestnet => "bsc-testnet",
|
||||
Chain::Arbitrum => "arbitrum",
|
||||
Chain::ArbitrumTestnet => "arbitrum-testnet",
|
||||
};
|
||||
|
||||
write!(formatter, "{}", chain)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ mod tests {
|
|||
let err = Client::new_from_env(Chain::XDai).unwrap_err();
|
||||
|
||||
assert!(matches!(err, EtherscanError::ChainNotSupported(_)));
|
||||
assert_eq!(err.to_string(), "chain XDai not supported");
|
||||
assert_eq!(err.to_string(), "chain xdai not supported");
|
||||
}
|
||||
|
||||
pub async fn run_at_least_duration(duration: Duration, block: impl Future) {
|
||||
|
|
Loading…
Reference in New Issue