Skip to content

Commit

Permalink
feat: OptimismGoerli
Browse files Browse the repository at this point in the history
  • Loading branch information
aya015757881 committed Oct 25, 2023
1 parent 40422dc commit 443fd53
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
7 changes: 5 additions & 2 deletions anychain-ethereum/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ pub use self::arbitrum::*;
pub mod arbitrum_goerli;
pub use self::arbitrum_goerli::*;

pub mod op_mainnet;
pub use self::op_mainnet::*;
pub mod optimism;
pub use self::optimism::*;

pub mod optimism_goerli;
pub use self::optimism_goerli::*;

pub mod huobi_eco;
pub use self::huobi_eco::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use std::{fmt, str::FromStr};

/// Represents an ETH mainnet
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct Op;
pub struct Optimism;

impl Network for Op {
const NAME: &'static str = "op";
impl Network for Optimism {
const NAME: &'static str = "optimism";
}

impl EthereumNetwork for Op {
impl EthereumNetwork for Optimism {
const CHAIN_ID: u32 = 10;
const NETWORK_ID: u32 = 10;
}

impl FromStr for Op {
impl FromStr for Optimism {
type Err = NetworkError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -28,7 +28,7 @@ impl FromStr for Op {
}
}

impl fmt::Display for Op {
impl fmt::Display for Optimism {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
Expand Down
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/optimism_goerli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::network::EthereumNetwork;
use anychain_core::{Network, NetworkError};

use serde::Serialize;
use std::{fmt, str::FromStr};

/// Represents an ETH mainnet
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct OptimismGoerli;

impl Network for OptimismGoerli {
const NAME: &'static str = "optimism goerli";
}

impl EthereumNetwork for OptimismGoerli {
const CHAIN_ID: u32 = 420;
const NETWORK_ID: u32 = 420;
}

impl FromStr for OptimismGoerli {
type Err = NetworkError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Self::NAME => Ok(Self),
_ => Err(NetworkError::InvalidNetwork(s.into())),
}
}
}

impl fmt::Display for OptimismGoerli {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}

0 comments on commit 443fd53

Please sign in to comment.