From 2507a8be0ed904363fe27fd3c4f7d21ef1fc2dcc Mon Sep 17 00:00:00 2001 From: Ajinkya Kulkarni Date: Thu, 5 Dec 2024 17:15:56 +0100 Subject: [PATCH] remove hardcoded config --- crates/utils/tcbinfo-updater/run.sh | 10 ++++++ crates/utils/tcbinfo-updater/src/main.rs | 45 +++++++++++++++--------- 2 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 crates/utils/tcbinfo-updater/run.sh diff --git a/crates/utils/tcbinfo-updater/run.sh b/crates/utils/tcbinfo-updater/run.sh new file mode 100644 index 0000000..c4dc7cb --- /dev/null +++ b/crates/utils/tcbinfo-updater/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# [network url] [chain-id] [contract address] [sender] [gas] [fees] + +cargo run -- \ + https://rpc-falcron.pion-1.ntrn.tech \ + pion-1 \ + neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk \ + ajinkya \ + 1000000 \ + "11000untrn" diff --git a/crates/utils/tcbinfo-updater/src/main.rs b/crates/utils/tcbinfo-updater/src/main.rs index 440d42f..cb911b8 100644 --- a/crates/utils/tcbinfo-updater/src/main.rs +++ b/crates/utils/tcbinfo-updater/src/main.rs @@ -5,7 +5,8 @@ use quoted_string::strip_dquotes; use quoted_string::to_content; use reqwest::Url; use serde_json::{json, Value}; - +use std::env; +use tendermint::chain::id::Id; type Fmspc = String; type Update = String; @@ -40,9 +41,9 @@ async fn get_fmspc_list() -> Vec { fmspc_list } -async fn upsert_tcbinfo() -> Result<(), &'static str> { +async fn upsert_tcbinfo(url: &str, contract_addr: &str, chain_id : Id, sender: &str, gas: u64, fees: &str) -> Result<(), &'static str> { - let testnet = Url::parse("https://rpc-falcron.pion-1.ntrn.tech").expect("couldn't parse network URL"); + let testnet = Url::parse(url).expect("couldn't parse network URL"); let client = CliClient::neutrond(testnet); let fmspc_list = get_fmspc_list().await; @@ -52,9 +53,8 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> { let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await; // assert!(verify_signature(tcbinfo.clone(), key)); - let contract_address = - "neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk" - .parse() + let contract_address = contract_addr + .parse() .expect("failed to parse contract address"); let query_msg = QueryMsg::GetTcbInfo { fmspc: fmspc.clone() }; @@ -67,28 +67,26 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> { }; - println!("{tcbinfo_on_chain} \n {tcbinfo_from_api}"); if tcbinfo_on_chain != tcbinfo_from_api { println!("updating on-chain TCBInfo for FMSPC: {fmspc}"); - let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id"); - let sender = "ajinkya"; + let execute_msg = ExecuteMsg { tcb_info: tcbinfo_from_api.to_string(), certificate: TCB_SIGNER.to_string(), time: None, }; - let _ = client + let res = client .tx_execute( &contract_address, &chain_id, - 1000000, + gas, sender, json!(execute_msg), - "11000untrn", + fees ) .await; - println!("done"); + println!("{res:?}"); std::thread::sleep(std::time::Duration::from_secs(5)); } else { println!("TCBInfo for FMSPC: {fmspc} up to date") @@ -97,9 +95,24 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> { Ok(()) } - - #[tokio::main] pub async fn main() { - upsert_tcbinfo().await.expect("TCBInfo update failed"); + let args: Vec = env::args().collect(); + let url = &args[1]; + let chain_id = &args[2]; + let contract_address : &str = &args[3]; + let sender: &str = &args[4]; + let gas: &u64 = &args[5].parse().expect("gas must be a u64 value"); + let fees: &str = &args[6]; + upsert_tcbinfo(url, contract_address, Id::try_from(chain_id.clone()).expect("invalid chain id"), sender, *gas, fees).await.expect("TCBInfo update failed"); } + +/*let url =; + let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id"); +contract_address = ; +let sender = ; +gas = 1000000, +fees = , + */ + +