Skip to content

Commit

Permalink
fix: unify name of supported chains with strum (gakonst#1249)
Browse files Browse the repository at this point in the history
* add strum

* update strum version

* whitespace

* revert strum

* using strum EnumVariantNames

* fix strum serialize kebab case and edge cases
  • Loading branch information
shawnharmsen authored May 16, 2022
1 parent d7b9c59 commit ceafcb2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
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 @@ -31,6 +31,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
11 changes: 8 additions & 3 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ use core::convert::TryFrom;
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

0 comments on commit ceafcb2

Please sign in to comment.