Skip to content

Commit

Permalink
Merge pull request #154 from 0xcregis/153-feat-anychain-ethereum-base…
Browse files Browse the repository at this point in the history
…-chain

feat: anychain-ethereum BASE chain
  • Loading branch information
shuimuliang authored Oct 27, 2023
2 parents df4186e + 582d25a commit 66cc0c0
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 10 deletions.
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.6"
version = "0.1.7"
keywords = ["blockchain", "crypto", "cryptocurrency", "ethereum", "wallet"]

# Workspace inherited keys
Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/arbitrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/arbitrum_goerli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/avalanche.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/avalanche_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/base.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 BASE mainnet
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct Base;

impl Network for Base {
const NAME: &'static str = "base";
}

impl EthereumNetwork for Base {
const CHAIN_ID: u32 = 8453;
const NETWORK_ID: u32 = 8453;
}

impl FromStr for Base {
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 Base {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAME)
}
}
35 changes: 35 additions & 0 deletions anychain-ethereum/src/network/base_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 BASE testnet
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct BaseGoerli;

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

impl EthereumNetwork for BaseGoerli {
const CHAIN_ID: u32 = 84531;
const NETWORK_ID: u32 = 84531;
}

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

pub mod base;
pub use self::base::*;

pub mod base_goerli;
pub use self::base_goerli::*;

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/mumbai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/okex_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

/// Represents a OKT mainnet
/// Represents a OKT testnet
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct OkexTestnet;

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/optimism_goerli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down
2 changes: 1 addition & 1 deletion anychain-ethereum/src/network/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anychain_core::{Network, NetworkError};
use serde::Serialize;
use std::{fmt, str::FromStr};

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

Expand Down

0 comments on commit 66cc0c0

Please sign in to comment.