Skip to content

Commit

Permalink
Removed generic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Oct 25, 2024
1 parent 85b7c74 commit cb04de7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tokio = { version = "1.39", features = ["full"] }
cw-orch = { path = "./cw-orch", version = "0.26.0" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.27.0" }
cw-orch-core = { path = "packages/cw-orch-core", version = "2.1.3" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.24.0" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.25.0" }
cw-orch-mock = { path = "packages/cw-orch-mock", version = "0.24.2" }
cw-orch-networks = { path = "packages/cw-orch-networks", version = "0.24.3" }

Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/src/sync/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<Sender: TxSender> TxHandler for DaemonBase<Sender> {
}

impl<Sender: TxSender> Stargate for DaemonBase<Sender> {
fn commit_any<R>(
fn commit_any(
&self,
msgs: Vec<prost_types::Any>,
memo: Option<&str>,
Expand Down
7 changes: 2 additions & 5 deletions cw-orch-interchain/examples/timeout_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use cw_orch::{environment::QueryHandler, prelude::*};
use cw_orch_interchain::prelude::*;
use cw_orch_interchain_core::IbcPacketOutcome;
use cw_orch_starship::Starship;
use ibc_proto::ibc::{
applications::transfer::v1::{MsgTransfer, MsgTransferResponse},
core::client::v1::Height,
};
use ibc_proto::ibc::{applications::transfer::v1::MsgTransfer, core::client::v1::Height};
use ibc_relayer_types::core::ics24_host::identifier::PortId;
use prost_types::Any;
fn main() -> cw_orch::anyhow::Result<()> {
Expand All @@ -33,7 +30,7 @@ fn main() -> cw_orch::anyhow::Result<()> {
.interchain_channel
.get_ordered_ports_from("juno-1")?;

let tx_resp = juno.commit_any::<MsgTransferResponse>(
let tx_resp = juno.commit_any(
vec![Any {
value: MsgTransfer {
source_port: channel.0.port.to_string(),
Expand Down
8 changes: 3 additions & 5 deletions packages/cw-orch-osmosis-test-tube/examples/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use cw_orch::prelude::*;
use cw_orch_osmosis_test_tube::OsmosisTestTube;
use osmosis_test_tube::osmosis_std::types::{
cosmos::base::v1beta1::Coin,
osmosis::tokenfactory::v1beta1::{
MsgCreateDenom, MsgCreateDenomResponse, MsgMint, MsgMintResponse,
},
osmosis::tokenfactory::v1beta1::{MsgCreateDenom, MsgMint},
};
use osmosis_test_tube::Account;
use prost::Message;
Expand All @@ -34,7 +32,7 @@ pub fn main() -> cw_orch::anyhow::Result<()> {
contract_counter.get_count()?;

// We create a new denom
chain.commit_any::<MsgCreateDenomResponse>(
chain.commit_any(
vec![Any {
type_url: MsgCreateDenom::TYPE_URL.to_string(),
value: MsgCreateDenom {
Expand All @@ -47,7 +45,7 @@ pub fn main() -> cw_orch::anyhow::Result<()> {
)?;
let denom = format!("factory/{}/{}", sender_addr, SUBDENOM);
// We mint some tokens
chain.commit_any::<MsgMintResponse>(
chain.commit_any(
vec![Any {
type_url: MsgMint::TYPE_URL.to_string(),
value: MsgMint {
Expand Down
35 changes: 20 additions & 15 deletions packages/cw-orch-osmosis-test-tube/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use cosmwasm_std::{Binary, Coin, Uint128};
use cw_orch_core::CwEnvError;
use cw_orch_mock::cw_multi_test::AppResponse;
use cw_orch_traits::Stargate;
use osmosis_test_tube::{
Account, Bank, ExecuteResponse, Gamm, Module, Runner, RunnerError, SigningAccount, Wasm,
};
use osmosis_test_tube::{Account, Bank, Gamm, Module, Runner, RunnerError, SigningAccount, Wasm};

// This should be the way to import stuff.
// But apparently osmosis-test-tube doesn't have the same dependencies as the test-tube package
Expand Down Expand Up @@ -381,27 +379,34 @@ impl BankSetter for OsmosisTestTube {
}

impl Stargate for OsmosisTestTube {
fn commit_any<R: prost::Message + Default>(
fn commit_any(
&self,
msgs: Vec<prost_types::Any>,
_memo: Option<&str>,
) -> Result<Self::Response, Self::Error> {
let msgs = msgs
.into_iter()
.map(|any| osmosis_test_tube::cosmrs::Any {
type_url: any.type_url,
value: any.value,
})
.collect();
let tx_response: ExecuteResponse<R> = self
let msgs = msgs.into_iter().map(|any| osmosis_test_tube::cosmrs::Any {
type_url: any.type_url,
value: any.value,
});
let tx_response = self
.app
.borrow()
.execute_multiple_raw(msgs, &self.sender)
.execute_with_selected_authenticators(msgs, &self.sender, &self.sender, &[])
.map_err(map_err)?;

Ok(AppResponse {
data: Some(Binary::new(tx_response.raw_data)),
events: tx_response.events,
data: None,
events: tx_response
.events
.into_iter()
.map(|e| {
let mut event = cosmwasm_std::Event::new(e.r#type);
for attribute in e.attributes {
event = event.add_attribute(attribute.key, attribute.value)
}
event
})
.collect(),
})
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/cw-orch-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-traits"
version = "0.24.1"
version = "0.25.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand All @@ -13,6 +13,4 @@ readme = "README.md"

[dependencies]
cw-orch-core = { workspace = true }
# Prost and Prost-types were kept at 0.11.9 here, because osmosis-test-tube doesn't support prost above 0.11.9
prost-types = { workspace = true }
prost = { workspace = true }
5 changes: 1 addition & 4 deletions packages/cw-orch-traits/src/stargate.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use cw_orch_core::environment::TxHandler;
use prost::Message;
use prost_types::Any;

/// Alows the execution of stargate like messages on cw-orch environments
pub trait Stargate: TxHandler {
/// Execute a custom abci/starship message on the environment
/// The message should already be encoded as protobuf any
/// We enforce a generic parameter to be able to unwrap the response (because of osmosis test tube for now)
/// This is however always a good practice to know which is the response to the tx type that you send
fn commit_any<R: Message + Default>(
fn commit_any(
&self,
msgs: Vec<Any>,
memo: Option<&str>,
Expand Down
14 changes: 5 additions & 9 deletions packages/interchain/proto/src/tokenfactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
use cw_orch_interchain_core::{
channel::InterchainChannel, IbcQueryHandler, InterchainEnv, InterchainError, NestedPacketsFlow,
};
use ibc_proto::ibc::{
applications::transfer::v1::MsgTransferResponse, apps::transfer::v1::MsgTransfer,
};
use osmosis_std::types::osmosis::tokenfactory::v1beta1::{
MsgCreateDenom, MsgCreateDenomResponse, MsgMint, MsgMintResponse,
};
use ibc_proto::ibc::apps::transfer::v1::MsgTransfer;
use osmosis_std::types::osmosis::tokenfactory::v1beta1::{MsgCreateDenom, MsgMint};
use prost::{Message, Name};
use tonic::transport::Channel;

Expand All @@ -32,7 +28,7 @@ pub fn create_denom<Chain: FullNode>(
}
.to_any();

chain.commit_any::<MsgCreateDenomResponse>(vec![any.into()], None)?;
chain.commit_any(vec![any.into()], None)?;

log::info!("Created denom {}", get_denom(chain, token_name));

Expand Down Expand Up @@ -71,7 +67,7 @@ pub fn mint<Chain: FullNode>(
}
.to_any();

chain.commit_any::<MsgMintResponse>(vec![any.into()], None)?;
chain.commit_any(vec![any.into()], None)?;

log::info!("Minted coins {} {}", amount, get_denom(chain, token_name));

Expand Down Expand Up @@ -115,7 +111,7 @@ pub fn transfer_tokens<Chain: IbcQueryHandler + FullNode, IBC: InterchainEnv<Cha

// We send tokens using the ics20 message over the channel that is passed as an argument
let send_tx = origin
.commit_any::<MsgTransferResponse>(
.commit_any(
vec![prost_types::Any {
type_url: MsgTransfer::full_name(),
value: msg_transfer.encode_to_vec(),
Expand Down

0 comments on commit cb04de7

Please sign in to comment.