Skip to content

Commit

Permalink
fix: strum EnumString
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Nov 2, 2024
1 parent 4fa9d6c commit 00a86e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
2 changes: 2 additions & 0 deletions rust/Cargo.lock

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

2 changes: 2 additions & 0 deletions rust/theoros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ rusoto_s3 = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
strum = { workspace = true, features = ["derive"] }
strum_macros = { workspace = true }
starknet = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] }
Expand Down
46 changes: 4 additions & 42 deletions rust/theoros/src/configs/evm_config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use strum_macros::EnumString;
use thiserror::Error;

pub const DEFAULT_CONFIG_PATH: &str = "evm_config.yaml";

/// Supported Chain identifiers
// Must reflect the EVM chains here:
// https://github.com/astraly-labs/pragma-monorepo/blob/main/typescript/pragma-utils/src/chains.ts
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, EnumString)]
#[strum(serialize_all = "snake_case")]
pub enum EvmChainName {
Mainnet,
Sepolia,
Expand Down Expand Up @@ -73,40 +72,3 @@ impl EvmConfig {
&self.chains
}
}

#[derive(Error, Debug)]
#[error("Unknown chain name: {0}")]
pub struct ParseChainError(String);

impl FromStr for EvmChainName {
type Err = ParseChainError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let chain_name = s.to_lowercase().replace('-', "_");
match chain_name.as_str() {
"mainnet" => Ok(Self::Mainnet),
"sepolia" => Ok(Self::Sepolia),
"holesky" => Ok(Self::Holesky),
"bsc" => Ok(Self::Bsc),
"bsc_testnet" => Ok(Self::BscTestnet),
"polygon" => Ok(Self::Polygon),
"polygon_testnet" => Ok(Self::PolygonTestnet),
"polygon_zk_evm" => Ok(Self::PolygonZkEvm),
"avalanche" => Ok(Self::Avalanche),
"fantom" => Ok(Self::Fantom),
"arbitrum" => Ok(Self::Arbitrum),
"optimism" => Ok(Self::Optimism),
"base" => Ok(Self::Base),
"scroll" => Ok(Self::Scroll),
"scroll_testnet" => Ok(Self::ScrollTestnet),
"scroll_sepolia_testnet" => Ok(Self::ScrollSepoliaTestnet),
"zircuit_testnet" => Ok(Self::ZircuitTestnet),
"plume_testnet" => Ok(Self::PlumeTestnet),
"worldchain" => Ok(Self::Worldchain),
"worldchain_testnet" => Ok(Self::WorldchainTestnet),
"zksync" => Ok(Self::Zksync),
"zksync_testnet" => Ok(Self::ZksyncTestnet),
_ => Err(ParseChainError(s.to_string())),
}
}
}

0 comments on commit 00a86e5

Please sign in to comment.