This commit is contained in:
Ajinkya Kulkarni 2024-12-05 13:03:39 +01:00
parent 7fbbf0fcbb
commit e490eac7c4

View file

@ -46,6 +46,14 @@ async fn get_fmspc_list() -> Vec<Fmspc> {
} }
async fn upsert_tcbinfo() -> Result<(), &'static str> { async fn upsert_tcbinfo() -> Result<(), &'static str> {
let testnet = Url::parse("https://rpc-falcron.pion-1.ntrn.tech").expect("couldn't parse network URL");
let client = CliClient::neutrond(testnet);
let fmspc_list = get_fmspc_list().await;
let mut store: HashMap<Fmspc, TcbInfo> = if Path::new("./standard").exists() { let mut store: HashMap<Fmspc, TcbInfo> = if Path::new("./standard").exists() {
let data = fs::read_to_string("./standard").expect("Unable to read file"); let data = fs::read_to_string("./standard").expect("Unable to read file");
serde_json::from_str(&data).unwrap() serde_json::from_str(&data).unwrap()
@ -54,10 +62,12 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
HashMap::new() HashMap::new()
}; };
let certificate = TCB_SIGNER.to_string(); let certificate = TCB_SIGNER.to_string();
let parsed_certificate = let parsed_certificate =
Certificate::from_pem(certificate.clone()).expect("failed to parse PEM"); Certificate::from_pem(certificate.clone()).expect("failed to parse PEM");
let fmspc_list = get_fmspc_list().await;
let key = VerifyingKey::from_sec1_bytes( let key = VerifyingKey::from_sec1_bytes(
parsed_certificate parsed_certificate
.tbs_certificate .tbs_certificate
@ -69,8 +79,17 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
.expect("Failed to decode public key"); .expect("Failed to decode public key");
for fmspc in fmspc_list { for fmspc in fmspc_list {
let tcbinfo = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
assert!(verify_signature(tcbinfo.clone(), key)); let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
// assert!(verify_signature(tcbinfo.clone(), key));
let contract_address =
"neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk"
.parse()
.expect("failed to parse contract address");
let query_msg = format!("{\"get_tcb_info\": {\"fmspc\": \"{}\"}}", fmspc) ;
let tcbinfo_on_chain = client.query_smart(&contract_address, query_msg).await;
println!("{tcbinfo_on_chain}");
exit();
let store_entry = if store.contains_key(&fmspc) { let store_entry = if store.contains_key(&fmspc) {
&store[&fmspc] &store[&fmspc]
} else { } else {
@ -80,15 +99,9 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
println!("updating local TCBInfo for FMSPC: {fmspc}"); println!("updating local TCBInfo for FMSPC: {fmspc}");
store.insert(fmspc.clone(), tcbinfo.clone()); store.insert(fmspc.clone(), tcbinfo.clone());
println!("updating on-chain TCBInfo for FMSPC: {fmspc}"); println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
let testnet = Url::parse("https://rpc-falcron.pion-1.ntrn.tech")
.expect("couldn't parse network URL");
let contract_address =
"neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk"
.parse()
.expect("failed to parse contract address");
let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id"); let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id");
let sender = "ajinkya"; let sender = "ajinkya";
let client = CliClient::neutrond(testnet);
let execute_msg = ExecuteMsg { let execute_msg = ExecuteMsg {
tcb_info: tcbinfo.to_string(), tcb_info: tcbinfo.to_string(),
certificate: certificate.clone(), certificate: certificate.clone(),
@ -104,7 +117,7 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
"11000untrn", "11000untrn",
) )
.await; .await;
println!("done: {res:?}"); println!("done");
std::thread::sleep(std::time::Duration::from_secs(5)); std::thread::sleep(std::time::Duration::from_secs(5));
} else { } else {
println!("TCBInfo for FMSPC: {fmspc} up to date") println!("TCBInfo for FMSPC: {fmspc} up to date")