op_alloy_registry/
chain_list.rsuse alloc::{string::String, vec::Vec};
#[derive(Debug, Clone, Default, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ChainList {
pub chains: Vec<Chain>,
}
#[derive(Debug, Clone, Default, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Chain {
pub name: String,
pub identifier: String,
pub chain_id: u64,
pub rpc: Vec<String>,
pub explorers: Vec<String>,
pub superchain_level: u64,
pub data_availability_type: String,
pub parent: SuperchainParent,
}
#[derive(Debug, Clone, Default, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SuperchainParent {
pub r#type: String,
pub chain: String,
}
impl SuperchainParent {
pub fn chain_id(&self) -> u64 {
match self.chain.as_ref() {
"mainnet" => 1,
"sepolia" => 11155111,
"sepolia-dev-0" => 11155421,
_ => 10,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn read_chain_list_file() {
let chain_list = include_str!("../etc/chainList.json");
let chains: Vec<Chain> = serde_json::from_str(chain_list).unwrap();
let base_chain = chains.iter().find(|c| c.name == "Base").unwrap();
assert_eq!(base_chain.chain_id, 8453);
}
}