Skip to content

Commit

Permalink
Merge pull request #143 from 0xcregis/142-feat-add-arbitrum-optimism-…
Browse files Browse the repository at this point in the history
…and-avalanche-for-anychain-ethereum

feat: AVAX, OP, ARB
  • Loading branch information
shuimuliang authored Oct 25, 2023
2 parents 79c63ba + 4ee1fb0 commit ea74122
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 1 deletion.
2 changes: 1 addition & 1 deletion anychain-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "anychain-ethereum"
description = "A Rust library for Ethereum-focused cryptocurrency wallets, enabling seamless transactions on the Ethereum blockchain"
version = "0.1.3"
version = "0.1.4"
keywords = ["blockchain", "crypto", "cryptocurrency", "ethereum", "wallet"]

# Workspace inherited keys
Expand Down
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/arbitrum.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 Arbitrum;

impl Network for Arbitrum {
const NAME: &'static str = "arbitrum";
}

impl EthereumNetwork for Arbitrum {
const CHAIN_ID: u32 = 42161;
const NETWORK_ID: u32 = 42161;
}

impl FromStr for Arbitrum {
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 Arbitrum {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/arbitrum_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 ArbitrumGoerli;

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

impl EthereumNetwork for ArbitrumGoerli {
const CHAIN_ID: u32 = 421613;
const NETWORK_ID: u32 = 421613;
}

impl FromStr for ArbitrumGoerli {
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 ArbitrumGoerli {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/avalanche.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 Avalanche;

impl Network for Avalanche {
const NAME: &'static str = "avalanche";
}

impl EthereumNetwork for Avalanche {
const CHAIN_ID: u32 = 43114;
const NETWORK_ID: u32 = 43114;
}

impl FromStr for Avalanche {
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 Avalanche {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/avalanche_testnet.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 AvalancheTestnet;

impl Network for AvalancheTestnet {
const NAME: &'static str = "ethereum";
}

impl EthereumNetwork for AvalancheTestnet {
const CHAIN_ID: u32 = 1;
const NETWORK_ID: u32 = 1;
}

impl FromStr for AvalancheTestnet {
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 AvalancheTestnet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}
15 changes: 15 additions & 0 deletions anychain-ethereum/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ pub use self::polygon::*;
pub mod mumbai;
pub use self::mumbai::*;

pub mod avalanche;
pub use self::avalanche::*;

pub mod avalanche_testnet;
pub use self::avalanche_testnet::*;

pub mod arbitrum;
pub use self::arbitrum::*;

pub mod arbitrum_goerli;
pub use self::arbitrum_goerli::*;

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

pub mod huobi_eco;
pub use self::huobi_eco::*;

Expand Down
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/op_mainnet.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 Op;

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

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

impl FromStr for Op {
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 Op {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}

0 comments on commit ea74122

Please sign in to comment.