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 crate::CwClient;
|
||||||
use serde_json::Value;
|
|
||||||
use color_eyre::{eyre::eyre, Help, Report, Result};
|
use color_eyre::{eyre::eyre, Help, Report, Result};
|
||||||
use cosmrs::{tendermint::chain::Id, AccountId};
|
use cosmrs::{tendermint::chain::Id, AccountId};
|
||||||
|
use quoted_string::strip_dquotes;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use quoted_string::strip_dquotes;
|
use serde_json::Value;
|
||||||
use crate::CwClient;
|
use std::process::Command;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum CliClientType {
|
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();
|
let bin = self.kind.bin();
|
||||||
if !self.is_bin_available(&bin) {
|
if !self.is_bin_available(&bin) {
|
||||||
return Err(eyre!("Binary '{}' not found in PATH", bin)).suggestion(format!(
|
return Err(eyre!("Binary '{}' not found in PATH", bin)).suggestion(format!(
|
||||||
|
@ -57,19 +57,21 @@ impl CliClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Command::new(self.kind.bin()))
|
Ok(Command::new(self.kind.bin()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn neutrond( url: Url) -> Self {
|
pub fn neutrond(url: Url) -> Self {
|
||||||
let mut command = Command::new("neutrond");
|
let mut command = Command::new("neutrond");
|
||||||
let command = command
|
let command = command
|
||||||
.arg("q")
|
.arg("q")
|
||||||
.arg("feemarket")
|
.arg("feemarket")
|
||||||
.arg("gas-price")
|
.arg("gas-price")
|
||||||
.arg("untrn")
|
.arg("untrn")
|
||||||
.arg ("-o")
|
.arg("-o")
|
||||||
.arg("json");
|
.arg("json");
|
||||||
let output = command.output().expect("command output failed").stdout;
|
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 json: Value = serde_json::from_str(&output_str).expect("could not convert to JSON");
|
||||||
let amount = &json["price"]["amount"].to_string();
|
let amount = &json["price"]["amount"].to_string();
|
||||||
|
|
||||||
|
@ -181,10 +183,9 @@ impl CwClient for CliClient {
|
||||||
.args(["tx", "wasm"])
|
.args(["tx", "wasm"])
|
||||||
.args(["execute", contract.as_ref(), &msg.to_string()])
|
.args(["execute", contract.as_ref(), &msg.to_string()])
|
||||||
.args(["--gas", "auto"])
|
.args(["--gas", "auto"])
|
||||||
.args(["--gas-prices", &self.gas_price])
|
.args(["--gas-prices", &self.gas_price])
|
||||||
.args(["--from", sender])
|
.args(["--from", sender])
|
||||||
.args(["--gas-adjustment", "1.3"])
|
.args(["--gas-adjustment", "1.3"])
|
||||||
|
|
||||||
.args(["--output", "json"])
|
.args(["--output", "json"])
|
||||||
.arg("-y");
|
.arg("-y");
|
||||||
let output = command.output()?;
|
let output = command.output()?;
|
||||||
|
@ -289,4 +290,3 @@ impl CwClient for CliClient {
|
||||||
Ok((trusted_height, trusted_hash))
|
Ok((trusted_height, trusted_hash))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl CwClient for GrpcClient {
|
||||||
chain_id: &TmChainId,
|
chain_id: &TmChainId,
|
||||||
gas: u64,
|
gas: u64,
|
||||||
_sender: &str,
|
_sender: &str,
|
||||||
msg: M
|
msg: M,
|
||||||
) -> Result<String, Self::Error> {
|
) -> Result<String, Self::Error> {
|
||||||
let tm_pubkey = self.sk.public_key();
|
let tm_pubkey = self.sk.public_key();
|
||||||
let sender = tm_pubkey
|
let sender = tm_pubkey
|
||||||
|
@ -256,7 +256,7 @@ mod tests {
|
||||||
2000000,
|
2000000,
|
||||||
"/* unused since we're getting the account from the sk */",
|
"/* unused since we're getting the account from the sk */",
|
||||||
json!([]),
|
json!([]),
|
||||||
"11000untrn",
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!("{}", tx_hash);
|
println!("{}", tx_hash);
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub trait CwClient {
|
||||||
chain_id: &Id,
|
chain_id: &Id,
|
||||||
gas: u64,
|
gas: u64,
|
||||||
sender: &str,
|
sender: &str,
|
||||||
msg: M
|
msg: M,
|
||||||
) -> Result<String, Self::Error>;
|
) -> Result<String, Self::Error>;
|
||||||
|
|
||||||
fn deploy<M: ToString>(
|
fn deploy<M: ToString>(
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use cw_client::{CliClient, CwClient};
|
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::strip_dquotes;
|
||||||
use quoted_string::test_utils::TestSpec;
|
use quoted_string::test_utils::TestSpec;
|
||||||
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 std::env;
|
||||||
use tendermint::chain::id::Id;
|
use tendermint::chain::id::Id;
|
||||||
|
|
||||||
type Fmspc = String;
|
type Fmspc = String;
|
||||||
type Update = String;
|
type Update = String;
|
||||||
|
@ -41,35 +41,44 @@ async fn get_fmspc_list() -> Vec<Fmspc> {
|
||||||
fmspc_list
|
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 network = Url::parse(url).expect("couldn't parse network URL");
|
||||||
let client = CliClient::neutrond(network);
|
let client = CliClient::neutrond(network);
|
||||||
let fmspc_list = get_fmspc_list().await;
|
let fmspc_list = get_fmspc_list().await;
|
||||||
|
|
||||||
for fmspc in fmspc_list {
|
for fmspc in fmspc_list {
|
||||||
|
|
||||||
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 = contract_addr
|
let contract_address = contract_addr
|
||||||
.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(),
|
||||||
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 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 {
|
if tcbinfo_on_chain != tcbinfo_from_api {
|
||||||
println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
|
println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
|
||||||
|
|
||||||
|
|
||||||
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(),
|
||||||
|
@ -79,9 +88,9 @@ async fn upsert_tcbinfo(url: &str, contract_addr: &str, chain_id : Id, sender: &
|
||||||
.tx_execute(
|
.tx_execute(
|
||||||
&contract_address,
|
&contract_address,
|
||||||
&chain_id,
|
&chain_id,
|
||||||
gas,
|
gas,
|
||||||
sender,
|
sender,
|
||||||
json!(execute_msg)
|
json!(execute_msg),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
println!("{res:?}");
|
println!("{res:?}");
|
||||||
|
@ -98,18 +107,16 @@ pub async fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let url = &args[1];
|
let url = &args[1];
|
||||||
let chain_id = &args[2];
|
let chain_id = &args[2];
|
||||||
let contract_address : &str = &args[3];
|
let contract_address: &str = &args[3];
|
||||||
let sender: &str = &args[4];
|
let sender: &str = &args[4];
|
||||||
let gas: &u64 = &args[5].parse().expect("gas must be a u64 value");
|
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