Use NODE var in scripts (#89)

Co-authored-by: hu55a1n1 <sufialhussaini@gmail.com>
This commit is contained in:
Ethan Buchman 2024-05-14 12:35:36 -04:00 committed by GitHub
parent 4ddddf19e4
commit 264f2ee2eb
3 changed files with 19 additions and 11 deletions

View file

@ -3,6 +3,7 @@ use std::path::PathBuf;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use cosmrs::{tendermint::chain::Id, AccountId}; use cosmrs::{tendermint::chain::Id, AccountId};
use displaydoc::Display; use displaydoc::Display;
use reqwest::Url;
use subtle_encoding::{bech32::decode as bech32_decode, Error as Bech32DecodeError}; use subtle_encoding::{bech32::decode as bech32_decode, Error as Bech32DecodeError};
use thiserror::Error; use thiserror::Error;
@ -14,12 +15,8 @@ pub struct Cli {
pub verbose: bool, pub verbose: bool,
/// The host to which to bind the API server. /// The host to which to bind the API server.
#[arg(short = 'H', long, default_value = "0.0.0.0")] #[arg(short = 'N', long, default_value = "http://127.0.0.1:26657")]
pub host: String, pub node: Url,
/// The port to which to bind the API server.
#[arg(short, long, default_value = "8000")]
pub port: u16,
/// Path to output CSV file /// Path to output CSV file
#[arg(short, long)] #[arg(short, long)]

View file

@ -76,7 +76,7 @@ async fn main() -> Result<(), DynError> {
} }
async fn sync_setoffs(cli: Cli) -> Result<(), DynError> { async fn sync_setoffs(cli: Cli) -> Result<(), DynError> {
let wasmd_client = CliWasmdClient; let wasmd_client = CliWasmdClient::new(cli.node);
let query_result: QueryResult<QueryAllSetoffsResponse> = let query_result: QueryResult<QueryAllSetoffsResponse> =
wasmd_client.query_smart(&cli.contract, json!("get_all_setoffs"))?; wasmd_client.query_smart(&cli.contract, json!("get_all_setoffs"))?;
let setoffs = query_result.data.setoffs; let setoffs = query_result.data.setoffs;
@ -145,7 +145,7 @@ async fn sync_obligations(cli: Cli, epoch_pk: &str) -> Result<(), DynError> {
info!("Encrypted {} intents", intents_enc.len()); info!("Encrypted {} intents", intents_enc.len());
let msg = create_wasm_msg(intents_enc); let msg = create_wasm_msg(intents_enc);
let wasmd_client = CliWasmdClient; let wasmd_client = CliWasmdClient::new(cli.node);
wasmd_client.tx_execute(&cli.contract, &cli.chain_id, 3000000, cli.user, msg)?; wasmd_client.tx_execute(&cli.contract, &cli.chain_id, 3000000, cli.user, msg)?;
Ok(()) Ok(())

View file

@ -1,6 +1,7 @@
use std::{error::Error, process::Command}; use std::{error::Error, process::Command};
use cosmrs::{tendermint::chain::Id, AccountId}; use cosmrs::{tendermint::chain::Id, AccountId};
use reqwest::Url;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub trait WasmdClient { pub trait WasmdClient {
@ -25,9 +26,6 @@ pub trait WasmdClient {
) -> Result<(), Self::Error>; ) -> Result<(), Self::Error>;
} }
#[derive(Clone, Debug)]
pub struct CliWasmdClient;
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct QueryResult<T> { pub struct QueryResult<T> {
pub data: T, pub data: T,
@ -43,6 +41,17 @@ impl<T: for<'any> Deserialize<'any>> FromVec for T {
} }
} }
#[derive(Clone, Debug)]
pub struct CliWasmdClient {
url: Url,
}
impl CliWasmdClient {
pub fn new(url: Url) -> Self {
Self { url }
}
}
impl WasmdClient for CliWasmdClient { impl WasmdClient for CliWasmdClient {
type Address = AccountId; type Address = AccountId;
type Query = serde_json::Value; type Query = serde_json::Value;
@ -56,6 +65,7 @@ impl WasmdClient for CliWasmdClient {
) -> Result<R, Self::Error> { ) -> Result<R, Self::Error> {
let mut wasmd = Command::new("wasmd"); let mut wasmd = Command::new("wasmd");
let command = wasmd let command = wasmd
.args(["--node", self.url.as_str()])
.args(["query", "wasm"]) .args(["query", "wasm"])
.args(["contract-state", "smart", contract.as_ref()]) .args(["contract-state", "smart", contract.as_ref()])
.arg(query.to_string()) .arg(query.to_string())
@ -78,6 +88,7 @@ impl WasmdClient for CliWasmdClient {
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let mut wasmd = Command::new("wasmd"); let mut wasmd = Command::new("wasmd");
let command = wasmd let command = wasmd
.args(["--node", self.url.as_str()])
.args(["tx", "wasm"]) .args(["tx", "wasm"])
.args(["execute", contract.as_ref(), &msg.to_string()]) .args(["execute", contract.as_ref(), &msg.to_string()])
.args(["--chain-id", chain_id.as_ref()]) .args(["--chain-id", chain_id.as_ref()])