use quoted_string::strip_dquotes; use serde_json::Value; use std::collections::HashMap; use std::fs; use cw_client::CliClient; type TcbInfo = Value; type Fmspc = String; type Update = String; fn get_tcbinfo(fmspc: Fmspc, update: Update) -> Value { let url = format!("https://api.trustedservices.intel.com/sgx/certification/v4/tcb?fmspc={fmspc}&update={update}"); println!("{url}"); let body: String = reqwest::blocking::get(url) .expect("url retrieval failed") .text() .expect("could not read https response"); let tcbinfo: Value = serde_json::from_str(&body).expect("could not convert to JSON"); tcbinfo } fn get_fmspc_list() -> Vec { let body: String = reqwest::blocking::get("https://api.trustedservices.intel.com/sgx/certification/v4/fmspcs") .expect("url retrieval failed") .text() .expect("could not read https response"); let fmspc_data: Vec = serde_json::from_str(&body).expect("could not convert to JSON"); let mut fmspc_list: Vec = Vec::new(); for item in fmspc_data.iter() { let fmspc: String = format!("{}", item["fmspc"]); fmspc_list.push(strip_dquotes(&fmspc).unwrap().to_string()); } println!("{:?}", fmspc_list); fmspc_list } fn init_database(update: &'static str) -> Result<(), &'static str> { if !(update == "early" || update == "standard") { return Err("invalid update argument"); } let mut store: HashMap = HashMap::new(); let fmspc_list = get_fmspc_list(); for fmspc in fmspc_list { store.insert(fmspc.clone(), get_tcbinfo(fmspc, update.to_string())); } let serialized = serde_json::to_string(&store).unwrap(); let path = format!("../{update}"); fs::write(path, serialized).expect("Unable to write file"); Ok(()) } pub fn main() { let data = fs::read_to_string("../standard").expect("Unable to read file"); let store: HashMap = serde_json::from_str(&data).unwrap(); let fmspc_list = get_fmspc_list(); for fmspc in fmspc_list { let tcbinfo = get_tcbinfo(fmspc.clone(), "standard".to_string()); let store_entry = &store[&fmspc]; if *store_entry != tcbinfo { println!("updating {fmspc}"); let testnet = "https://rpc-falcron.pion-1.ntrn.tech"; let client = CliClient::neutrond(testnet); let tx_hash = client.tx_execute(); } else { println!("data up to date") } } // let _ = init_database("standard"); println!("ok") // } // } }