From cdd11858f6821c06f93d3aab061872c2af67f440 Mon Sep 17 00:00:00 2001 From: Ajinkya Kulkarni Date: Tue, 3 Dec 2024 10:13:37 +0100 Subject: [PATCH] WIP async --- crates/utils/tcbinfo-updater/src/main.rs | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/utils/tcbinfo-updater/src/main.rs b/crates/utils/tcbinfo-updater/src/main.rs index 8dc5dd4..aebd7c2 100644 --- a/crates/utils/tcbinfo-updater/src/main.rs +++ b/crates/utils/tcbinfo-updater/src/main.rs @@ -22,10 +22,10 @@ impl ToString for ExecMsg { } } -fn get_tcbinfo(fmspc: Fmspc, update: Update) -> Value { +async fn get_tcbinfo(fmspc: Fmspc, update: Update) -> Value { let url = format!("https://api.trustedservices.intel.com/sgx/certification/v4/tcb?fmspc={fmspc}&update={update}"); - let body: String = reqwest::blocking::get(url) - + let body: String = reqwest::get(url) + .await .expect("url retrieval failed") .text() .expect("could not read https response"); @@ -33,9 +33,9 @@ fn get_tcbinfo(fmspc: Fmspc, update: Update) -> Value { tcbinfo } -fn get_fmspc_list() -> Vec { +async fn get_fmspc_list() -> Vec { let body: String = - reqwest::blocking::get("https://api.trustedservices.intel.com/sgx/certification/v4/fmspcs") + reqwest::get("https://api.trustedservices.intel.com/sgx/certification/v4/fmspcs").await .expect("url retrieval failed") .text() .expect("could not read https response"); @@ -49,7 +49,8 @@ fn get_fmspc_list() -> Vec { fmspc_list } -fn upsert_tcbinfo() -> Result<(), &'static str> { + +async fn upsert_tcbinfo() -> Result<(), &'static str> { let data = fs::read_to_string("./standard").expect("Unable to read file"); let mut store: HashMap = serde_json::from_str(&data).unwrap(); @@ -71,11 +72,11 @@ fn upsert_tcbinfo() -> Result<(), &'static str> { certificate: TCB_SIGNER.to_string(), time: None, }}; - // if let Err(e) = - let _ = client.tx_execute(&contract_address, &chain_id, 200000, &sender, execute_msg, "200000untrn"); - // { - // eprintln!("Error: {}", e); - // } + if let Err(e) = + client.tx_execute(&contract_address, &chain_id, 200000, &sender, execute_msg, "200000untrn").await + { + eprintln!("Error: {}", e); + } println!("done"); } else { @@ -90,7 +91,7 @@ fn upsert_tcbinfo() -> Result<(), &'static str> { // } } -// #[tokio::main] -pub fn main() { - upsert_tcbinfo().expect("TCBInfo update failed"); +#[tokio::main] +pub async fn main() { + upsert_tcbinfo().await.expect("TCBInfo update failed"); }