cleanup
This commit is contained in:
parent
f8c7bd5b88
commit
069dc8374e
4 changed files with 61 additions and 54 deletions
|
@ -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 {
|
||||
|
@ -69,7 +69,9 @@ impl CliClient {
|
|||
.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();
|
||||
|
||||
|
@ -184,7 +186,6 @@ impl CwClient for CliClient {
|
|||
.args(["--gas-prices", &self.gas_price])
|
||||
.args(["--from", sender])
|
||||
.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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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::to_content;
|
||||
|
@ -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
|
||||
.parse()
|
||||
.expect("failed to parse contract address");
|
||||
let query_msg = QueryMsg::GetTcbInfo { fmspc: fmspc.clone() };
|
||||
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()
|
||||
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(),
|
||||
|
@ -81,7 +90,7 @@ async fn upsert_tcbinfo(url: &str, contract_addr: &str, chain_id : Id, sender: &
|
|||
&chain_id,
|
||||
gas,
|
||||
sender,
|
||||
json!(execute_msg)
|
||||
json!(execute_msg),
|
||||
)
|
||||
.await;
|
||||
println!("{res:?}");
|
||||
|
@ -101,15 +110,13 @@ pub async fn main() {
|
|||
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 = ,
|
||||
*/
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue