Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: unify name of supported chains with strum #1249

Merged
merged 6 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
.vscode
/.envrc
.idea
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethers-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bytes = { version = "1.1.0", features = ["serde"] }
hex = { version = "0.4.3", default-features = false, features = ["std"] }
once_cell = { version = "1.10.0", optional = true }
unicode-xid = "0.2.3"
strum = { version = "0.24", features = ["derive"] }

# macros feature enabled dependencies
cargo_metadata = { version = "0.14.2", optional = true }
Expand Down
13 changes: 9 additions & 4 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@ use serde::Deserialize;
use thiserror::Error;

use core::convert::TryFrom;
use std::{default, fmt, str::FromStr};
use std::{convert::TryInto, default, fmt, str::FromStr};

use crate::types::U256;
use strum::{EnumVariantNames};

#[derive(Debug, Clone, Error)]
#[error("Failed to parse chain: {0}")]
pub struct ParseChainError(String);

#[repr(u64)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "kebab-case")]
pub enum Chain {
Mainnet = 1,
Ropsten = 3,
Rinkeby = 4,
Goerli = 5,
Kovan = 42,
#[strum(serialize = "xdai")]
XDai = 100,
Polygon = 137,
Fantom = 250,
Expand All @@ -33,12 +36,14 @@ pub enum Chain {
Moonriver = 1285,
Optimism = 10,
OptimismKovan = 69,
BinanceSmartChain = 56,
BinanceSmartChainTestnet = 97,
Arbitrum = 42161,
ArbitrumTestnet = 421611,
Cronos = 25,
CronosTestnet = 338,
#[strum(serialize = "bsc")]
BinanceSmartChain = 56,
#[strum(serialize = "bsc-testnet")]
BinanceSmartChainTestnet = 97,
}

impl fmt::Display for Chain {
Expand Down