ethers-rs/crates/ethers-providers/src/networks.rs

35 lines
1002 B
Rust
Raw Normal View History

2020-05-24 14:41:12 +00:00
//! Networks are used inside wallets to ensure type-safety across networks. That way
//! a transaction that is designed to work with testnet does not accidentally work
//! with mainnet because the URL was changed.
2020-05-27 15:43:43 +00:00
use ethers_types::{Address, H160, U64};
2020-05-24 14:41:12 +00:00
pub trait Network {
const CHAIN_ID: Option<U64>;
2020-05-27 15:43:43 +00:00
const ENS_ADDRESS: Option<Address>;
2020-05-24 14:41:12 +00:00
// TODO: Default providers? e.g. `mainnet.infura.io/XXX`?
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Mainnet;
impl Network for Mainnet {
const CHAIN_ID: Option<U64> = Some(U64([1]));
2020-05-27 15:43:43 +00:00
// 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
const ENS_ADDRESS: Option<Address> = Some(H160([
// cannot set type aliases as constructors
0, 0, 0, 0, 0, 12, 46, 7, 78, 198, 154, 13, 251, 41, 151, 186, 108, 125, 46, 30,
]));
2020-05-24 14:41:12 +00:00
}
/// No EIP155
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2020-05-27 15:43:43 +00:00
pub struct Any;
2020-05-24 14:41:12 +00:00
2020-05-27 15:43:43 +00:00
impl Network for Any {
2020-05-24 14:41:12 +00:00
const CHAIN_ID: Option<U64> = None;
2020-05-27 15:43:43 +00:00
const ENS_ADDRESS: Option<Address> = None;
2020-05-24 14:41:12 +00:00
}