Skip to content

Commit 58cc195

Browse files
KayanskiBuckram123
andauthored
Added bank send function (#526)
* Added bank send function * formatting * Update packages/cw-orch-core/src/environment/tx_handler.rs Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> * Changelog * Insta * Updated versions and published * Changelog --------- Co-authored-by: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com>
1 parent df39fe9 commit 58cc195

File tree

28 files changed

+224
-143
lines changed

28 files changed

+224
-143
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# cw-orchestrator Changelog
22

3-
## Unpublished
3+
## Cw-orch-daemon 0.29.0 - cw-orch-core 2.1.4 [16. December 2024]
44

55
- [networks] Replaced union testnet-8 by union-testnet-9
66

77
### Breaking
88

99
- [interchain-core] Modify the structure and the names of the IBC analysis and following structure.
1010
- [osmosis-test-tube] Update `osmosis-test-tube` to "v27.0.0"
11+
- [daemon]: Move the bank_send method from the Wallet to the TxSender trait.
12+
13+
### Added
14+
15+
- [core] bank_send method on TxHandler to facilitate sending funds in script
1116

1217
## 0.26.0 [8. October 2024]
1318

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ serde = { version = "1.0.208", default-features = false, features = ["derive"]
4444
tokio = { version = "1.39", features = ["full"] }
4545

4646
cw-orch = { path = "./cw-orch", version = "0.27.0" }
47-
cw-orch-core = { path = "packages/cw-orch-core", version = "2.1.3" }
48-
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.28.0" }
47+
cw-orch-core = { path = "packages/cw-orch-core", version = "2.1.4" }
48+
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.29.0" }
4949
cw-orch-mock = { path = "packages/cw-orch-mock", version = "0.24.2" }
5050
cw-orch-networks = { path = "packages/cw-orch-networks", version = "0.24.3" }
5151
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.25.0" }

cw-orch-daemon/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = { workspace = true }
88
name = "cw-orch-daemon"
99
readme = "../README.md"
1010
repository = { workspace = true }
11-
version = "0.28.1"
11+
version = "0.29.0"
1212

1313
exclude = [".env"]
1414

cw-orch-daemon/examples/daemon-capabilities.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::str::FromStr;
33
use cosmrs::{tx::Msg, AccountId, Coin, Denom};
44
use cosmwasm_std::{coins, Addr};
55
// ANCHOR: full_counter_example
6-
use cw_orch_daemon::senders::tx::TxSender;
6+
use cw_orch::prelude::Stargate;
7+
use cw_orch::prelude::TxHandler;
78
use cw_orch_daemon::DaemonBuilder;
89
use cw_orch_networks::networks;
910

@@ -19,13 +20,11 @@ pub fn main() -> anyhow::Result<()> {
1920

2021
// We commit the tx (also resimulates the tx)
2122
// ANCHOR: send_tx
22-
let wallet = daemon.sender();
2323

24-
let rt = daemon.rt_handle.clone();
25-
rt.block_on(wallet.bank_send(
24+
daemon.bank_send(
2625
&Addr::unchecked("<address-of-my-sister>"),
27-
coins(345, "ujunox"),
28-
))?;
26+
&coins(345, "ujunox"),
27+
)?;
2928
// ANCHOR_END: send_tx
3029

3130
// ANCHOR: cosmrs_tx
@@ -45,22 +44,27 @@ pub fn main() -> anyhow::Result<()> {
4544
denom: Denom::from_str("ujuno").unwrap(),
4645
},
4746
};
48-
rt.block_on(wallet.commit_tx(vec![tx_msg.clone()], None))?;
47+
daemon
48+
.rt_handle
49+
.block_on(daemon.sender().commit_tx(vec![tx_msg.clone()], None))?;
4950
// ANCHOR_END: cosmrs_tx
5051

5152
// ANCHOR: any_tx
52-
rt.block_on(wallet.commit_tx_any(
53-
vec![cosmrs::Any {
53+
daemon.commit_any(
54+
vec![prost_types::Any {
5455
type_url: "/cosmos.staking.v1beta1.MsgBeginRedelegate".to_string(),
5556
value: tx_msg.to_any().unwrap().value,
5657
}],
5758
None,
58-
))?;
59+
)?;
5960
// ANCHOR_END: any_tx
6061

6162
// ANCHOR: simulate_tx
62-
let (gas_needed, fee_needed) =
63-
rt.block_on(wallet.simulate(vec![tx_msg.to_any().unwrap()], None))?;
63+
let (gas_needed, fee_needed) = daemon.rt_handle.block_on(
64+
daemon
65+
.sender()
66+
.simulate(vec![tx_msg.to_any().unwrap()], None),
67+
)?;
6468

6569
log::info!(
6670
"Submitting this transaction will necessitate:

cw-orch-daemon/examples/hd_index.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ pub fn main() -> anyhow::Result<()> {
1616
.authz_granter(&Addr::unchecked(LOCAL_JUNO_GRANTER));
1717
let chain = Daemon::builder(network).build_sender(sender)?;
1818

19-
chain.rt_handle.block_on(
20-
chain
21-
.sender()
22-
.bank_send(&Addr::unchecked(LOCAL_JUNO_GRANTER), coins(10000, "ujuno")),
23-
)?;
19+
chain.bank_send(&Addr::unchecked(LOCAL_JUNO_GRANTER), &coins(10000, "ujuno"))?;
2420

2521
Ok(())
2622
}

cw-orch-daemon/examples/manual_sender.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use cw_orch_daemon::queriers::Node;
55
use cw_orch_daemon::senders::builder::SenderBuilder;
66
use cw_orch_daemon::senders::query::QuerySender;
77
use cw_orch_daemon::tx_broadcaster::assert_broadcast_code_cosm_response;
8-
use cw_orch_daemon::{DaemonBase, GrpcChannel, TxBuilder};
8+
use cw_orch_daemon::{parse_cw_coins, DaemonBase, GrpcChannel, TxBuilder};
99

1010
use cw_orch_daemon::{CosmTxResponse, DaemonError};
1111

12+
use cosmrs::bank::MsgSend;
1213
use cosmrs::proto::cosmos;
1314
use cosmrs::proto::cosmos::auth::v1beta1::BaseAccount;
1415
use cosmrs::proto::cosmos::vesting::v1beta1::PeriodicVestingAccount;
@@ -20,6 +21,7 @@ use cw_orch::prelude::*;
2021
use cw_orch_core::environment::ChainInfoOwned;
2122
use prost::Message;
2223
use std::io::{self, Write};
24+
use std::str::FromStr;
2325
use std::sync::Arc;
2426
use tonic::transport::Channel;
2527

@@ -122,6 +124,22 @@ impl TxSender for ManualSender {
122124
fn account_id(&self) -> AccountId {
123125
self.sender.clone().to_string().parse().unwrap()
124126
}
127+
128+
async fn bank_send(
129+
&self,
130+
recipient: &Addr,
131+
coins: &[cosmwasm_std::Coin],
132+
) -> Result<CosmTxResponse, DaemonError> {
133+
let acc_id = self.msg_sender()?;
134+
135+
let msg_send = MsgSend {
136+
from_address: acc_id,
137+
to_address: AccountId::from_str(recipient.as_str())?,
138+
amount: parse_cw_coins(coins)?,
139+
};
140+
141+
self.commit_tx(vec![msg_send], Some("sending tokens")).await
142+
}
125143
}
126144

127145
impl ManualSender {

cw-orch-daemon/src/core.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ impl AsyncWasmQuerier for DaemonAsync {
444444
}
445445
}
446446

447-
pub(crate) fn parse_cw_coins(
448-
coins: &[cosmwasm_std::Coin],
449-
) -> Result<Vec<cosmrs::Coin>, DaemonError> {
447+
pub fn parse_cw_coins(coins: &[cosmwasm_std::Coin]) -> Result<Vec<cosmrs::Coin>, DaemonError> {
450448
coins
451449
.iter()
452450
.map(|cosmwasm_std::Coin { amount, denom }| {

cw-orch-daemon/src/senders/cosmos.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use super::{
55
tx::TxSender,
66
};
77
use crate::{
8-
core::parse_cw_coins,
98
cosmos_modules::{self, auth::BaseAccount},
109
env::{DaemonEnvVars, LOCAL_MNEMONIC_ENV_NAME, MAIN_MNEMONIC_ENV_NAME, TEST_MNEMONIC_ENV_NAME},
1110
error::DaemonError,
@@ -19,7 +18,6 @@ use crate::{
1918
use bitcoin::secp256k1::{All, Secp256k1, Signing};
2019
use cosmos_modules::vesting::PeriodicVestingAccount;
2120
use cosmrs::{
22-
bank::MsgSend,
2321
crypto::secp256k1::SigningKey,
2422
proto::traits::Message,
2523
tendermint::chain::Id,
@@ -32,7 +30,7 @@ use cw_orch_core::{
3230
environment::{AccessConfig, ChainInfoOwned, ChainKind},
3331
CoreEnvVars, CwEnvError,
3432
};
35-
use std::{str::FromStr, sync::Arc};
33+
use std::sync::Arc;
3634
use tonic::transport::Channel;
3735

3836
#[cfg(feature = "eth")]
@@ -163,22 +161,6 @@ impl Wallet {
163161
Signer::account_id(self).to_string()
164162
}
165163

166-
pub async fn bank_send(
167-
&self,
168-
recipient: &Addr,
169-
coins: Vec<cosmwasm_std::Coin>,
170-
) -> Result<CosmTxResponse, DaemonError> {
171-
let acc_id = self.msg_sender()?;
172-
173-
let msg_send = MsgSend {
174-
from_address: acc_id,
175-
to_address: AccountId::from_str(recipient.as_str())?,
176-
amount: parse_cw_coins(&coins)?,
177-
};
178-
179-
self.commit_tx(vec![msg_send], Some("sending tokens")).await
180-
}
181-
182164
/// Computes the gas needed for submitting a transaction
183165
pub async fn calculate_gas(
184166
&self,

cw-orch-daemon/src/senders/cosmos_batch.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
use crate::{DaemonBase, INSTANTIATE_2_TYPE_URL};
2-
1+
use super::builder::SenderBuilder;
2+
use super::cosmos::Wallet;
3+
use super::query::QuerySender;
4+
use super::tx::TxSender;
5+
use crate::parse_cw_coins;
36
use crate::{error::DaemonError, tx_resp::CosmTxResponse};
4-
7+
use crate::{DaemonBase, INSTANTIATE_2_TYPE_URL};
8+
use cosmrs::bank::MsgSend;
59
use cosmrs::proto::cosmwasm::wasm::v1::{MsgInstantiateContract, MsgStoreCode};
610
use cosmrs::{AccountId, Any};
711
use cosmwasm_std::Addr;
812
use cw_orch_core::environment::ChainInfoOwned;
913
use cw_orch_core::log::transaction_target;
1014
use options::CosmosBatchOptions;
1115
use prost::Name;
12-
16+
use std::str::FromStr;
1317
use std::sync::{Arc, Mutex};
1418

15-
use super::builder::SenderBuilder;
16-
use super::cosmos::Wallet;
17-
use super::query::QuerySender;
18-
use super::tx::TxSender;
19-
2019
pub type BatchDaemon = DaemonBase<CosmosBatchSender>;
2120

2221
pub mod options {
@@ -132,4 +131,20 @@ impl TxSender for CosmosBatchSender {
132131
fn account_id(&self) -> AccountId {
133132
self.sender.account_id()
134133
}
134+
135+
async fn bank_send(
136+
&self,
137+
recipient: &Addr,
138+
coins: &[cosmwasm_std::Coin],
139+
) -> Result<CosmTxResponse, DaemonError> {
140+
let acc_id = self.msg_sender()?;
141+
142+
let msg_send = MsgSend {
143+
from_address: acc_id,
144+
to_address: AccountId::from_str(recipient.as_str())?,
145+
amount: parse_cw_coins(coins)?,
146+
};
147+
148+
self.commit_tx(vec![msg_send], Some("sending tokens")).await
149+
}
135150
}

cw-orch-daemon/src/senders/sign.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::str::FromStr;
2+
13
use crate::{
4+
parse_cw_coins,
25
queriers::Node,
36
tx_broadcaster::{
47
account_sequence_strategy, assert_broadcast_code_cosm_response, insufficient_fee_strategy,
@@ -7,6 +10,7 @@ use crate::{
710
CosmTxResponse, DaemonError, QuerySender, TxBuilder, TxSender,
811
};
912
use cosmrs::{
13+
bank::MsgSend,
1014
proto::cosmos::authz::v1beta1::MsgExec,
1115
tendermint::chain::Id,
1216
tx::{Body, Fee, Raw, SignDoc, SignerInfo},
@@ -132,4 +136,20 @@ impl<T: Signer + Sync> TxSender for T {
132136
Ok(self.account_id())
133137
}
134138
}
139+
140+
async fn bank_send(
141+
&self,
142+
recipient: &Addr,
143+
coins: &[cosmwasm_std::Coin],
144+
) -> Result<CosmTxResponse, DaemonError> {
145+
let acc_id = self.msg_sender()?;
146+
147+
let msg_send = MsgSend {
148+
from_address: acc_id,
149+
to_address: AccountId::from_str(recipient.as_str())?,
150+
amount: parse_cw_coins(coins)?,
151+
};
152+
153+
self.commit_tx(vec![msg_send], Some("sending tokens")).await
154+
}
135155
}

0 commit comments

Comments
 (0)