pub const ROOM_MARKET_ABI: &str = include_str!("../public/ABI/RoomMarket.json");
pub const TOKEN_ABI: &str = include_str!("../public/ABI/Token.json");
pub const SIMPLE_GAME_ABI: &str = include_str!("../public/ABI/SimpleGame.json");
pub const DEFAULT_NETWORK: Network = Network::Localhost;
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)]
pub enum Network {
Localhost,
Holesky,
Sepolia,
OpBNBTestnet,
Other,
}
impl Network {
pub fn from_str(s: &str) -> Self {
match s {
"localhost" => Network::Localhost,
"holesky" => Network::Holesky,
"sepolia" => Network::Sepolia,
"opbnbtestnet" => Network::OpBNBTestnet,
_ => Network::Other,
}
}
pub fn to_str<'a>(&self) -> &'a str {
match self {
Network::Localhost => "localhost",
Network::Holesky => "holesky",
Network::Sepolia => "sepolia",
Network::OpBNBTestnet => "opbnbtestnet",
Network::Other => "other",
}
}
pub fn from_chain_id(chain_id: u64) -> Self {
match chain_id {
17000 => Network::Holesky,
11155111 => Network::Sepolia,
5611 => Network::OpBNBTestnet,
_ => DEFAULT_NETWORK,
}
}
}
#[derive(Default)]
pub struct NetworkCurrency {
pub name: String,
pub symbol: String,
pub decimals: i32,
}
#[derive(Default)]
pub struct NetworkConfig {
pub chain_id: i32,
pub chain_name: String,
pub rpc_urls: Vec<String>,
pub block_explorer_urls: Vec<String>,
pub icon_urls: Vec<String>,
pub native_currency: NetworkCurrency,
}
impl NetworkConfig {
pub fn from(network: Network) -> NetworkConfig {
match network {
Network::Localhost => {
let mut nc = NetworkConfig::default();
nc.rpc_urls = vec!["http://127.0.0.1:8545".to_owned()];
nc
}
Network::Holesky => NetworkConfig {
chain_id: 17000,
chain_name: "Holesky".to_owned(),
rpc_urls: vec!["https://1rpc.io/holesky".to_owned()],
icon_urls: vec!["https://icons.llamao.fi/icons/chains/rsz_ethereum.jpg".to_owned()],
block_explorer_urls: vec!["https://holesky.beaconcha.in/".to_owned()],
native_currency: NetworkCurrency {
name: "Holesky ETH".to_owned(),
symbol: "ETH".to_owned(),
decimals: 18,
},
},
Network::Sepolia => NetworkConfig {
chain_id: 11155111,
chain_name: "Sepolia".to_owned(),
rpc_urls: vec!["https://rpc.sepolia.org".to_owned()],
icon_urls: vec!["https://icons.llamao.fi/icons/chains/rsz_ethereum.jpg".to_owned()],
block_explorer_urls: vec!["https://sepolia.etherscan.io/".to_owned()],
native_currency: NetworkCurrency {
name: "Sepolia ETH".to_owned(),
symbol: "ETH".to_owned(),
decimals: 18,
},
},
Network::OpBNBTestnet => NetworkConfig {
chain_id: 5611,
chain_name: "opBNB Testnet".to_owned(),
rpc_urls: vec!["https://opbnb-testnet-rpc.bnbchain.org".to_owned()],
icon_urls: vec!["https://icons.llamao.fi/icons/chains/rsz_opbnb.jpg".to_owned()],
block_explorer_urls: vec!["http://testnet.opbnbscan.com/".to_owned()],
native_currency: NetworkCurrency {
name: "opBNB ETH".to_owned(),
symbol: "tBNB".to_owned(),
decimals: 18,
},
},
Network::Other => panic!("No config for other network"),
}
}
}