From 264f2ee2eb5977c7e958d2078afda240dc16bb2a Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 14 May 2024 12:35:36 -0400 Subject: [PATCH] Use NODE var in scripts (#89) Co-authored-by: hu55a1n1 --- utils/cycles-sync/src/cli.rs | 9 +++------ utils/cycles-sync/src/main.rs | 4 ++-- utils/cycles-sync/src/wasmd_client.rs | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/utils/cycles-sync/src/cli.rs b/utils/cycles-sync/src/cli.rs index c539dea..dfb72bb 100644 --- a/utils/cycles-sync/src/cli.rs +++ b/utils/cycles-sync/src/cli.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use clap::{Parser, Subcommand}; use cosmrs::{tendermint::chain::Id, AccountId}; use displaydoc::Display; +use reqwest::Url; use subtle_encoding::{bech32::decode as bech32_decode, Error as Bech32DecodeError}; use thiserror::Error; @@ -14,12 +15,8 @@ pub struct Cli { pub verbose: bool, /// The host to which to bind the API server. - #[arg(short = 'H', long, default_value = "0.0.0.0")] - pub host: String, - - /// The port to which to bind the API server. - #[arg(short, long, default_value = "8000")] - pub port: u16, + #[arg(short = 'N', long, default_value = "http://127.0.0.1:26657")] + pub node: Url, /// Path to output CSV file #[arg(short, long)] diff --git a/utils/cycles-sync/src/main.rs b/utils/cycles-sync/src/main.rs index eb1f45b..d959449 100644 --- a/utils/cycles-sync/src/main.rs +++ b/utils/cycles-sync/src/main.rs @@ -76,7 +76,7 @@ async fn main() -> 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 = wasmd_client.query_smart(&cli.contract, json!("get_all_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()); 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)?; Ok(()) diff --git a/utils/cycles-sync/src/wasmd_client.rs b/utils/cycles-sync/src/wasmd_client.rs index b87698b..3a7ac59 100644 --- a/utils/cycles-sync/src/wasmd_client.rs +++ b/utils/cycles-sync/src/wasmd_client.rs @@ -1,6 +1,7 @@ use std::{error::Error, process::Command}; use cosmrs::{tendermint::chain::Id, AccountId}; +use reqwest::Url; use serde::{Deserialize, Serialize}; pub trait WasmdClient { @@ -25,9 +26,6 @@ pub trait WasmdClient { ) -> Result<(), Self::Error>; } -#[derive(Clone, Debug)] -pub struct CliWasmdClient; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct QueryResult { pub data: T, @@ -43,6 +41,17 @@ impl 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 { type Address = AccountId; type Query = serde_json::Value; @@ -56,6 +65,7 @@ impl WasmdClient for CliWasmdClient { ) -> Result { let mut wasmd = Command::new("wasmd"); let command = wasmd + .args(["--node", self.url.as_str()]) .args(["query", "wasm"]) .args(["contract-state", "smart", contract.as_ref()]) .arg(query.to_string()) @@ -78,6 +88,7 @@ impl WasmdClient for CliWasmdClient { ) -> Result<(), Self::Error> { let mut wasmd = Command::new("wasmd"); let command = wasmd + .args(["--node", self.url.as_str()]) .args(["tx", "wasm"]) .args(["execute", contract.as_ref(), &msg.to_string()]) .args(["--chain-id", chain_id.as_ref()])