remove hardcoded config

This commit is contained in:
Ajinkya Kulkarni 2024-12-05 17:15:56 +01:00
parent 87193616f6
commit 2507a8be0e
2 changed files with 39 additions and 16 deletions

View file

@ -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"

View file

@ -5,7 +5,8 @@ use quoted_string::strip_dquotes;
use quoted_string::to_content; use quoted_string::to_content;
use reqwest::Url; use reqwest::Url;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::env;
use tendermint::chain::id::Id;
type Fmspc = String; type Fmspc = String;
type Update = String; type Update = String;
@ -40,9 +41,9 @@ async fn get_fmspc_list() -> Vec<Fmspc> {
fmspc_list 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 client = CliClient::neutrond(testnet);
let fmspc_list = get_fmspc_list().await; 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; let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
// assert!(verify_signature(tcbinfo.clone(), key)); // assert!(verify_signature(tcbinfo.clone(), key));
let contract_address = let contract_address = contract_addr
"neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk" .parse()
.parse()
.expect("failed to parse contract address"); .expect("failed to parse contract address");
let query_msg = QueryMsg::GetTcbInfo { fmspc: fmspc.clone() }; 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 { if tcbinfo_on_chain != tcbinfo_from_api {
println!("updating on-chain TCBInfo for FMSPC: {fmspc}"); 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 { let execute_msg = ExecuteMsg {
tcb_info: tcbinfo_from_api.to_string(), tcb_info: tcbinfo_from_api.to_string(),
certificate: TCB_SIGNER.to_string(), certificate: TCB_SIGNER.to_string(),
time: None, time: None,
}; };
let _ = client let res = client
.tx_execute( .tx_execute(
&contract_address, &contract_address,
&chain_id, &chain_id,
1000000, gas,
sender, sender,
json!(execute_msg), json!(execute_msg),
"11000untrn", fees
) )
.await; .await;
println!("done"); println!("{res:?}");
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")
@ -97,9 +95,24 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
Ok(()) Ok(())
} }
#[tokio::main] #[tokio::main]
pub async fn main() { pub async fn main() {
upsert_tcbinfo().await.expect("TCBInfo update failed"); let args: Vec<String> = 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 = ,
*/