This commit is contained in:
Ajinkya Kulkarni 2025-02-25 15:09:28 +01:00
parent f8c7bd5b88
commit 069dc8374e
4 changed files with 61 additions and 54 deletions

View file

@ -1,11 +1,11 @@
use std::process::Command;
use serde_json::Value;
use crate::CwClient;
use color_eyre::{eyre::eyre, Help, Report, Result};
use cosmrs::{tendermint::chain::Id, AccountId};
use quoted_string::strip_dquotes;
use reqwest::Url;
use serde::de::DeserializeOwned;
use quoted_string::strip_dquotes;
use crate::CwClient;
use serde_json::Value;
use std::process::Command;
#[derive(Clone, Debug)]
pub enum CliClientType {
@ -47,7 +47,7 @@ impl CliClient {
}
}
fn new_command(&self) -> Result<Command> {
fn new_command(&self) -> Result<Command> {
let bin = self.kind.bin();
if !self.is_bin_available(&bin) {
return Err(eyre!("Binary '{}' not found in PATH", bin)).suggestion(format!(
@ -57,29 +57,31 @@ impl CliClient {
}
Ok(Command::new(self.kind.bin()))
}
pub fn neutrond( url: Url) -> Self {
let mut command = Command::new("neutrond");
}
pub fn neutrond(url: Url) -> Self {
let mut command = Command::new("neutrond");
let command = command
.arg("q")
.arg("feemarket")
.arg("gas-price")
.arg("untrn")
.arg ("-o")
.arg("-o")
.arg("json");
let output = command.output().expect("command output failed").stdout;
let output_str: String = std::str::from_utf8(&output).expect("unable to parse command output").to_string();
let output_str: String = std::str::from_utf8(&output)
.expect("unable to parse command output")
.to_string();
let json: Value = serde_json::from_str(&output_str).expect("could not convert to JSON");
let amount = &json["price"]["amount"].to_string();
let price = strip_dquotes(amount)
.expect("strip dquotes failed")
.parse::<f64>()
.expect("couldn't parse gas price");
let gas_price = format!("{}untrn", price);
Self {
kind: CliClientType::Neutrond,
url,
@ -181,10 +183,9 @@ impl CwClient for CliClient {
.args(["tx", "wasm"])
.args(["execute", contract.as_ref(), &msg.to_string()])
.args(["--gas", "auto"])
.args(["--gas-prices", &self.gas_price])
.args(["--gas-prices", &self.gas_price])
.args(["--from", sender])
.args(["--gas-adjustment", "1.3"])
.args(["--gas-adjustment", "1.3"])
.args(["--output", "json"])
.arg("-y");
let output = command.output()?;
@ -289,4 +290,3 @@ impl CwClient for CliClient {
Ok((trusted_height, trusted_hash))
}
}

View file

@ -87,7 +87,7 @@ impl CwClient for GrpcClient {
chain_id: &TmChainId,
gas: u64,
_sender: &str,
msg: M
msg: M,
) -> Result<String, Self::Error> {
let tm_pubkey = self.sk.public_key();
let sender = tm_pubkey
@ -256,7 +256,7 @@ mod tests {
2000000,
"/* unused since we're getting the account from the sk */",
json!([]),
"11000untrn",
)
.await?;
println!("{}", tx_hash);

View file

@ -36,7 +36,7 @@ pub trait CwClient {
chain_id: &Id,
gas: u64,
sender: &str,
msg: M
msg: M,
) -> Result<String, Self::Error>;
fn deploy<M: ToString>(

View file

@ -1,12 +1,12 @@
use cw_client::{CliClient, CwClient};
use quartz_tcbinfo_msgs::{QueryMsg, ExecuteMsg};
use quartz_tcbinfo_msgs::{ExecuteMsg, QueryMsg};
use quoted_string::strip_dquotes;
use quoted_string::test_utils::TestSpec;
use quoted_string::test_utils::TestSpec;
use quoted_string::to_content;
use reqwest::Url;
use serde_json::{json, Value};
use std::env;
use tendermint::chain::id::Id;
use tendermint::chain::id::Id;
type Fmspc = String;
type Update = String;
@ -41,35 +41,44 @@ async fn get_fmspc_list() -> Vec<Fmspc> {
fmspc_list
}
async fn upsert_tcbinfo(url: &str, contract_addr: &str, chain_id : Id, sender: &str, gas: u64) -> Result<(), &'static str> {
async fn upsert_tcbinfo(
url: &str,
contract_addr: &str,
chain_id: Id,
sender: &str,
gas: u64,
) -> Result<(), &'static str> {
let network = Url::parse(url).expect("couldn't parse network URL");
let client = CliClient::neutrond(network);
let fmspc_list = get_fmspc_list().await;
for fmspc in fmspc_list {
let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
// assert!(verify_signature(tcbinfo.clone(), key));
let contract_address = contract_addr
let contract_address = contract_addr
.parse()
.expect("failed to parse contract address");
let query_msg = QueryMsg::GetTcbInfo { fmspc: fmspc.clone() };
let tcbinfo_on_chain = { if let Ok(res) = client.query_smart::<Value>(&contract_address, json!(query_msg)).await {
to_content::<TestSpec>(&res["data"]["tcb_info"].to_string()).unwrap().to_string()
} else {
"".to_string()
}
let query_msg = QueryMsg::GetTcbInfo {
fmspc: fmspc.clone(),
};
let tcbinfo_on_chain = {
if let Ok(res) = client
.query_smart::<Value>(&contract_address, json!(query_msg))
.await
{
to_content::<TestSpec>(&res["data"]["tcb_info"].to_string())
.unwrap()
.to_string()
} else {
"".to_string()
}
};
if tcbinfo_on_chain != tcbinfo_from_api {
println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
let execute_msg = ExecuteMsg {
tcb_info: tcbinfo_from_api.to_string(),
certificate: TCB_SIGNER.to_string(),
@ -79,9 +88,9 @@ async fn upsert_tcbinfo(url: &str, contract_addr: &str, chain_id : Id, sender: &
.tx_execute(
&contract_address,
&chain_id,
gas,
gas,
sender,
json!(execute_msg)
json!(execute_msg),
)
.await;
println!("{res:?}");
@ -98,18 +107,16 @@ pub async fn main() {
let args: Vec<String> = env::args().collect();
let url = &args[1];
let chain_id = &args[2];
let contract_address : &str = &args[3];
let contract_address: &str = &args[3];
let sender: &str = &args[4];
let gas: &u64 = &args[5].parse().expect("gas must be a u64 value");
upsert_tcbinfo(url, contract_address, Id::try_from(chain_id.clone()).expect("invalid chain id"), sender, *gas).await.expect("TCBInfo update failed");
upsert_tcbinfo(
url,
contract_address,
Id::try_from(chain_id.clone()).expect("invalid chain id"),
sender,
*gas,
)
.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 = ,
*/