ethers-rs/src/signers/networks.rs

36 lines
894 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.
use crate::types::U64;
pub trait Network {
const CHAIN_ID: Option<U64>;
// 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]));
}
/// No EIP155
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct EIP155Disabled;
// EIP155 being disabled means no chainId will be used
impl Network for EIP155Disabled {
const CHAIN_ID: Option<U64> = None;
}
pub mod instantiated {
use super::*;
2020-05-24 15:40:16 +00:00
use crate::signers::Wallet;
2020-05-24 14:41:12 +00:00
pub type MainnetWallet = Wallet<Mainnet>;
pub type AnyWallet = Wallet<EIP155Disabled>;
}