fix: unify name of supported chains with strum (#1249)
* add strum * update strum version * whitespace * revert strum * using strum EnumVariantNames * fix strum serialize kebab case and edge cases
This commit is contained in:
parent
d7b9c59f00
commit
ceafcb250b
|
@ -1,3 +1,4 @@
|
|||
/target
|
||||
.vscode
|
||||
/.envrc
|
||||
.idea
|
|
@ -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"
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue