Skip to content

Commit

Permalink
upgrade cw-orch-cli to 0.25 cw-orch
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 committed Sep 4, 2024
1 parent 1379823 commit 42c490d
Show file tree
Hide file tree
Showing 27 changed files with 235 additions and 363 deletions.
8 changes: 4 additions & 4 deletions cw-orch-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ async-trait = { version = "0.1" }

# Cosmos
cosmwasm-std = { workspace = true }
cw-utils = "1.0.3"
cw20 = { version = "1" }
cw-ownable = { version = "0.5.1" }
cosmrs = { version = "0.15.0", features = ["cosmwasm", "grpc"] }
cw-utils = "2.0.0"
cw20 = { version = "2.0" }
cw-ownable = { version = "2.0.0" }
cosmrs = { workspace = true, features = ["cosmwasm", "grpc"] }
ibc-chain-registry = { workspace = true }

# Serde
Expand Down
8 changes: 4 additions & 4 deletions cw-orch-cli/src/commands/action/asset/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::CosmosContext;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

mod query_cw20;
mod query_native;
mod send_cw20;
mod send_native;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

use super::CosmosContext;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = CosmosContext)]
pub struct AssetCommands {
Expand Down
42 changes: 12 additions & 30 deletions cw-orch-cli/src/commands/action/asset/query_cw20/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use cw20::BalanceResponse;
use cw_orch::{daemon::GrpcChannel, environment::ChainInfoOwned, tokio::runtime::Runtime};

use cosmrs::proto::cosmwasm::wasm::v1::{
query_client::QueryClient, QuerySmartContractStateRequest,
};

use crate::types::CliAddress;

use super::CosmosContext;

use cw20::BalanceResponse;
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = QueryCw20Output)]
Expand All @@ -35,29 +31,15 @@ impl QueryCw20Output {
.address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let chain_data: ChainInfoOwned = chain.into();
let msg = serde_json::to_vec(&cw20::Cw20QueryMsg::Balance {
address: account_id.to_string(),
})?;

let rt = Runtime::new()?;

rt.block_on(async {
let grpc_channel =
GrpcChannel::connect(&chain_data.grpc_urls, chain_data.chain_id.as_str()).await?;
let mut client = QueryClient::new(grpc_channel);

let resp = client
.smart_contract_state(QuerySmartContractStateRequest {
address: cw20_account_id.to_string(),
query_data: msg,
})
.await?;
let parsed_output: BalanceResponse = serde_json::from_slice(&resp.into_inner().data)?;
println!("{}", serde_json::to_string_pretty(&parsed_output)?);

color_eyre::Result::<(), color_eyre::Report>::Ok(())
})?;
let daemon = chain.daemon_querier()?;

let balance: BalanceResponse = daemon.query(
&(cw20::Cw20QueryMsg::Balance {
address: account_id.to_string(),
}),
&Addr::unchecked(cw20_account_id),
)?;
println!("{}", serde_json::to_string_pretty(&balance)?);

Ok(QueryCw20Output)
}
Expand Down
39 changes: 15 additions & 24 deletions cw-orch-cli/src/commands/action/asset/query_native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cw_orch::{daemon::GrpcChannel, environment::ChainInfoOwned, tokio::runtime::Runtime};

use crate::types::{CliAddress, CliSkippable};

use super::CosmosContext;

use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = QueryNativeOutput)]
Expand All @@ -28,28 +28,19 @@ impl QueryNativeOutput {
.address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;

let chain_data: ChainInfoOwned = chain.into();
let rt = Runtime::new()?;

rt.block_on(async {
let grpc_channel =
GrpcChannel::connect(&chain_data.grpc_urls, chain_data.chain_id.as_str()).await?;
let bank = cw_orch::daemon::queriers::Bank::new_async(grpc_channel);
if let Some(denom) = denom {
let balance = bank
._balance(account_id.to_string(), Some(denom))
.await?
.swap_remove(0);
println!("balance: {balance}")
} else {
let balances = bank._balance(account_id.to_string(), None).await?;
// `cosmwasm_std::Coins` have nice display
let coins = cosmwasm_std::Coins::try_from(balances).unwrap();
println!("balances: {coins}")
}
color_eyre::Result::<(), color_eyre::Report>::Ok(())
})?;
let addr = Addr::unchecked(account_id);

let daemon = chain.daemon_querier()?;

if let Some(denom) = denom {
let balance = daemon.balance(&addr, Some(denom))?.swap_remove(0);
println!("balance: {balance}")
} else {
let balances = daemon.balance(&addr, None)?;
// `cosmwasm_std::Coins` have nice display
let coins = cosmwasm_std::Coins::try_from(balances).unwrap();
println!("balances: {coins}")
}

Ok(QueryNativeOutput)
}
Expand Down
39 changes: 13 additions & 26 deletions cw-orch-cli/src/commands/action/asset/send_cw20/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use cosmwasm_std::Uint128;
use cw_orch::{
daemon::{CosmTxResponse, DaemonAsync, TxSender},
tokio::runtime::Runtime,
};

use crate::{
log::LogOutput,
types::{keys::seed_phrase_for_id, CliAddress},
};

use super::CosmosContext;

use cosmwasm_std::Uint128;
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = SendCw20Output)]
Expand Down Expand Up @@ -47,28 +44,18 @@ impl SendCw20Output {
.cw20_address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let cw20_addr = Addr::unchecked(cw20_account_id);

let seed = seed_phrase_for_id(&scope.signer)?;
let cw20_msg = cw20::Cw20ExecuteMsg::Transfer {
recipient: to_address_account_id.to_string(),
amount: Uint128::new(scope.amount),
};
let msg = serde_json::to_vec(&cw20_msg)?;
let rt = Runtime::new()?;

let resp = rt.block_on(async {
let daemon = DaemonAsync::builder(chain).mnemonic(seed).build().await?;

let exec_msg = cosmrs::cosmwasm::MsgExecuteContract {
sender: daemon.sender().account_id(),
contract: cw20_account_id,
msg,
funds: vec![],
};

let resp = daemon.sender().commit_tx(vec![exec_msg], None).await?;
color_eyre::Result::<CosmTxResponse, color_eyre::Report>::Ok(resp)
})?;
let daemon = chain.daemon(seed)?;
let resp = daemon.execute(
&cw20::Cw20ExecuteMsg::Transfer {
recipient: to_address_account_id.to_string(),
amount: Uint128::new(scope.amount),
},
&[],
&cw20_addr,
)?;

resp.log(chain.chain_info());

Expand Down
15 changes: 8 additions & 7 deletions cw-orch-cli/src/commands/action/asset/send_native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use color_eyre::eyre::Context;
use cw_orch::{daemon::Daemon, tokio::runtime::Runtime};

use crate::{
log::LogOutput,
types::{keys::seed_phrase_for_id, CliAddress, CliCoins},
};

use super::CosmosContext;

use color_eyre::eyre::Context;
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = SendNativeOutput)]
Expand Down Expand Up @@ -45,15 +45,16 @@ impl SendNativeOutput {
.to_address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let to_address = Addr::unchecked(to_address);

let seed = seed_phrase_for_id(&scope.signer)?;
let coins = scope.coins.clone().into();

let rt = Runtime::new()?;

let daemon = Daemon::builder(chain).mnemonic(seed).build()?;
let daemon = chain.daemon(seed)?;

let resp = rt.block_on(daemon.sender().bank_send(to_address.as_ref(), coins))?;
let resp = daemon
.rt_handle
.block_on(daemon.sender().bank_send(&to_address, coins))?;
resp.log(chain.chain_info());

Ok(SendNativeOutput)
Expand Down
40 changes: 18 additions & 22 deletions cw-orch-cli/src/commands/action/cosmwasm/execute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use color_eyre::eyre::Context;
use cw_orch::daemon::TxSender;
use cw_orch::{daemon::CosmTxResponse, prelude::DaemonAsync, tokio::runtime::Runtime};

use crate::log::LogOutput;
use crate::types::keys::seed_phrase_for_id;
use crate::types::CliAddress;
use crate::{commands::action::CosmosContext, types::CliCoins};
use crate::{
commands::action::CosmosContext,
log::LogOutput,
types::{keys::seed_phrase_for_id, CliAddress, CliCoins},
};

use super::msg_type;

use color_eyre::eyre::Context;
use cw_orch::daemon::TxSender;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = ExecuteWasmOutput)]
Expand Down Expand Up @@ -63,20 +63,16 @@ impl ExecuteWasmOutput {
let coins = (&scope.coins).try_into()?;
let msg = msg_type::msg_bytes(scope.msg.clone(), scope.msg_type.clone())?;

let rt = Runtime::new()?;
let resp = rt.block_on(async {
let daemon = DaemonAsync::builder(chain).mnemonic(seed).build().await?;

let exec_msg = cosmrs::cosmwasm::MsgExecuteContract {
sender: daemon.sender().account_id(),
contract: contract_account_id,
msg,
funds: coins,
};

let resp = daemon.sender().commit_tx(vec![exec_msg], None).await?;
color_eyre::Result::<CosmTxResponse, color_eyre::Report>::Ok(resp)
})?;
let daemon = chain.daemon(seed)?;
let exec_msg = cosmrs::cosmwasm::MsgExecuteContract {
sender: daemon.sender().account_id(),
contract: contract_account_id,
msg,
funds: coins,
};
let resp = daemon
.rt_handle
.block_on(daemon.sender().commit_tx(vec![exec_msg], None))?;

resp.log(chain.chain_info());

Expand Down
36 changes: 15 additions & 21 deletions cw-orch-cli/src/commands/action/cosmwasm/instantiate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
use color_eyre::eyre::Context;
use cw_orch::{
daemon::{CosmTxResponse, TxSender},
prelude::{DaemonAsync, IndexResponse},
tokio::runtime::Runtime,
};

use crate::{
commands::action::CosmosContext,
log::LogOutput,
Expand All @@ -13,6 +6,9 @@ use crate::{

use super::msg_type;

use color_eyre::eyre::Context;
use cw_orch::{daemon::TxSender, prelude::*};

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = InstantiateWasmOutput)]
Expand Down Expand Up @@ -66,22 +62,20 @@ impl InstantiateWasmOutput {
let coins = (&scope.coins).try_into()?;
let msg = msg_type::msg_bytes(scope.msg.clone(), scope.msg_type.clone())?;

let rt = Runtime::new()?;
let resp = rt.block_on(async {
let daemon = DaemonAsync::builder(chain).mnemonic(seed).build().await?;
let daemon = chain.daemon(seed)?;

let exec_msg = cosmrs::cosmwasm::MsgInstantiateContract {
sender: daemon.sender().account_id(),
admin: scope.admin.clone().0.map(|a| a.parse()).transpose()?,
code_id: scope.code_id,
label: Some(scope.label.clone()),
msg,
funds: coins,
};
let init_msg = cosmrs::cosmwasm::MsgInstantiateContract {
sender: daemon.sender().account_id(),
admin: scope.admin.clone().0.map(|a| a.parse()).transpose()?,
code_id: scope.code_id,
label: Some(scope.label.clone()),
msg,
funds: coins,
};

let resp = daemon.sender().commit_tx(vec![exec_msg], None).await?;
color_eyre::Result::<CosmTxResponse, color_eyre::Report>::Ok(resp)
})?;
let resp = daemon
.rt_handle
.block_on(daemon.sender().commit_tx(vec![init_msg], None))?;
resp.log(chain.chain_info());

let address = resp.instantiated_contract_address()?;
Expand Down
8 changes: 4 additions & 4 deletions cw-orch-cli/src/commands/action/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::CosmosContext;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

mod execute;
mod instantiate;
pub mod msg_type;
mod query;
mod store;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

use super::CosmosContext;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = CosmosContext)]
pub struct CwCommands {
Expand Down
6 changes: 3 additions & 3 deletions cw-orch-cli/src/commands/action/cosmwasm/query/code.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::commands::action::CosmosContext;

use cw_orch::{daemon::DaemonBuilder, environment::ChainInfoOwned, prelude::*};
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
Expand All @@ -19,8 +19,8 @@ impl QueryCodeOutput {
) -> color_eyre::eyre::Result<Self> {
let chain = previous_context.chain;

let chain_data: ChainInfoOwned = chain.into();
let daemon = DaemonBuilder::new(chain_data.clone()).build_sender(())?;
let daemon = chain.daemon_querier()?;

let code_info = daemon.wasm_querier().code(scope.code_id)?;
println!("{}", serde_json::to_string_pretty(&code_info)?);

Expand Down
Loading

0 comments on commit 42c490d

Please sign in to comment.