diff --git a/.gitignore b/.gitignore index 3668f4ec..252650b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .vscode /.envrc +.idea \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5050e6a4..08375caf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,6 +1260,7 @@ dependencies = [ "rlp-derive", "serde", "serde_json", + "strum", "syn", "thiserror", "tiny-keccak", @@ -3618,6 +3619,28 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96acfc1b70604b8b2f1ffa4c57e59176c7dbb05d556c71ecd2f5498a1dee7f8" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "subtle" version = "2.4.1" diff --git a/ethers-core/Cargo.toml b/ethers-core/Cargo.toml index cea4e00a..a788cbcd 100644 --- a/ethers-core/Cargo.toml +++ b/ethers-core/Cargo.toml @@ -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 } diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 2eb5bafc..1a0c5269 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -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, @@ -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 {