From 51742e3b57ecccfff09cb3908417b8a551c0bdab Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 18 Sep 2024 12:43:56 +0000 Subject: [PATCH 1/6] Added accessorfor all chains --- packages/interchain/interchain-core/src/env.rs | 13 +++++++++++++ .../interchain-daemon/src/interchain_env.rs | 4 ++++ .../interchain/interchain-mock/src/interchain.rs | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/packages/interchain/interchain-core/src/env.rs b/packages/interchain/interchain-core/src/env.rs index c760eb481..e831ae55a 100644 --- a/packages/interchain/interchain-core/src/env.rs +++ b/packages/interchain/interchain-core/src/env.rs @@ -138,6 +138,19 @@ pub trait InterchainEnv { /// ``` fn get_chain(&self, chain_id: impl ToString) -> Result; + /// Returns every chain registered within the environment. + /// To get a single chain, use [`InterchainEnv::get_chain`] + /// ``` rust + /// use cw_orch::prelude::*; + /// use cw_orch_interchain::prelude::*; + /// use counter_contract::CounterContract; + /// let interchain = MockBech32InterchainEnv::new(vec![("osmosis-1","osmo"),("archway-1","arch")]); + /// + /// let all_chains = interchain.chains().unwrap(); + /// + /// ``` + fn chains(&self) -> Result, Self::Error>; + /// This triggers channel creation between 2 chains /// Returns a channel creation receipt as well as as the connection_id on the src_chain side /// This code is only for internal use and for most cases shouldn't be used outside of the [InterchainEnv::create_channel] function diff --git a/packages/interchain/interchain-daemon/src/interchain_env.rs b/packages/interchain/interchain-daemon/src/interchain_env.rs index 10f191bfc..91fb2713b 100644 --- a/packages/interchain/interchain-daemon/src/interchain_env.rs +++ b/packages/interchain/interchain-daemon/src/interchain_env.rs @@ -289,6 +289,10 @@ impl InterchainEnv for DaemonInterchain { Ok(ibc_trail) } + + fn chains(&self) -> Result, Self::Error> { + Ok(self.daemons.values().cloned().collect()) + } } impl DaemonInterchain { diff --git a/packages/interchain/interchain-mock/src/interchain.rs b/packages/interchain/interchain-mock/src/interchain.rs index 920ca6bec..cc3ec8584 100644 --- a/packages/interchain/interchain-mock/src/interchain.rs +++ b/packages/interchain/interchain-mock/src/interchain.rs @@ -358,6 +358,10 @@ impl InterchainEnv> for MockInterchainEnvBase { Ok(analysis_result) } + + fn chains(&self) -> Result>, Self::Error> { + Ok(self.mocks.values().cloned().collect()) + } } fn get_events(tx: &AppResponse, event: &str) -> Vec { From e341f4756ee53f1a4a9ff0ac3c18d9d73a7c7656 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 23 Sep 2024 11:40:06 +0000 Subject: [PATCH 2/6] Merge --- Cargo.toml | 8 ++++---- cw-orch-interchain/Cargo.toml | 2 +- cw-orch-interchain/examples/doc_daemon.rs | 6 ++---- cw-orch-interchain/examples/follow_packets_txhash.rs | 2 +- packages/interchain/interchain-core/Cargo.toml | 2 +- packages/interchain/interchain-daemon/Cargo.toml | 2 +- .../interchain/interchain-daemon/src/interchain_env.rs | 2 -- packages/interchain/interchain-mock/Cargo.toml | 2 +- packages/interchain/proto/Cargo.toml | 2 +- 9 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d78a9da48..eb541f224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,10 +61,10 @@ cw-orch-fns-derive = { path = "packages/macros/cw-orch-fns-derive", version = "0 # cw-orch-osmosis-test-tube = { version = "0.3.0", path = "packages/cw-orch-osmosis-test-tube" } # Interchain -cw-orch-interchain = { path = "cw-orch-interchain", version = "0.4.0" } -cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.5.0" } -cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.5.0" } -cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.5.0" } +cw-orch-interchain = { path = "cw-orch-interchain", version = "0.5.0" } +cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.6.0" } +cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.6.0" } +cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.6.0" } cw-orch-starship = { path = "packages/interchain/starship", version = "0.5.0" } # cw-orch-proto = { path = "packages/interchain/proto", version = "0.5.0" } # prost, tonic, cosmrs bump locked by osmosis (we use it for tokenfactory) diff --git a/cw-orch-interchain/Cargo.toml b/cw-orch-interchain/Cargo.toml index 46d48e8a6..b15e7140a 100644 --- a/cw-orch-interchain/Cargo.toml +++ b/cw-orch-interchain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain" -version = "0.4.0" +version = "0.5.0" authors = { workspace = true } edition = { workspace = true } license = { workspace = true } diff --git a/cw-orch-interchain/examples/doc_daemon.rs b/cw-orch-interchain/examples/doc_daemon.rs index 659a9e77e..f5212bf22 100644 --- a/cw-orch-interchain/examples/doc_daemon.rs +++ b/cw-orch-interchain/examples/doc_daemon.rs @@ -8,10 +8,8 @@ use cw_orch_interchain::{ fn create_daemon_env() -> cw_orch::anyhow::Result { // ANCHOR: DAEMON_INTERCHAIN_CREATION // This will create `Daemon` structures associated with chains `LOCAL_JUNO` and `LOCAL_OSMO` - let mut interchain = DaemonInterchain::new( - vec![(LOCAL_JUNO, None), (LOCAL_OSMO, None)], - &ChannelCreationValidator, - )?; + let mut interchain = + DaemonInterchain::new(vec![LOCAL_JUNO, LOCAL_OSMO], &ChannelCreationValidator)?; let local_juno: Daemon = interchain.get_chain("testing")?; let _local_osmo: Daemon = interchain.get_chain("localosmosis")?; diff --git a/cw-orch-interchain/examples/follow_packets_txhash.rs b/cw-orch-interchain/examples/follow_packets_txhash.rs index a9a6e6fcc..c084b4f88 100644 --- a/cw-orch-interchain/examples/follow_packets_txhash.rs +++ b/cw-orch-interchain/examples/follow_packets_txhash.rs @@ -28,7 +28,7 @@ fn follow_by_tx_hash() -> cw_orch::anyhow::Result<()> { let src_chain = OSMOSIS_1; let interchain = DaemonInterchain::new( - vec![(src_chain.clone(), None), (dst_chain, None)], + vec![src_chain.clone(), dst_chain], &ChannelCreationValidator, )?; diff --git a/packages/interchain/interchain-core/Cargo.toml b/packages/interchain/interchain-core/Cargo.toml index d15cf8142..eacca7184 100644 --- a/packages/interchain/interchain-core/Cargo.toml +++ b/packages/interchain/interchain-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-core" -version = "0.5.0" +version = "0.6.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/packages/interchain/interchain-daemon/Cargo.toml b/packages/interchain/interchain-daemon/Cargo.toml index b662d7b8d..69d14b4d2 100644 --- a/packages/interchain/interchain-daemon/Cargo.toml +++ b/packages/interchain/interchain-daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-daemon" -version = "0.5.0" +version = "0.6.0" description = "An interchain intergration crate for interacting with actual chain nodes (via gRPC)" authors.workspace = true edition.workspace = true diff --git a/packages/interchain/interchain-daemon/src/interchain_env.rs b/packages/interchain/interchain-daemon/src/interchain_env.rs index 91fb2713b..0317b559a 100644 --- a/packages/interchain/interchain-daemon/src/interchain_env.rs +++ b/packages/interchain/interchain-daemon/src/interchain_env.rs @@ -41,8 +41,6 @@ pub struct DaemonInterchain { rt_handle: Handle, } -type Mnemonic = String; - impl DaemonInterchain { /// Builds a new [`DaemonInterchain`] instance. /// For use with starship, we advise to use [`cw_orch_starship::Starship::interchain_env`] instead diff --git a/packages/interchain/interchain-mock/Cargo.toml b/packages/interchain/interchain-mock/Cargo.toml index 34f962ef3..6c1fc899f 100644 --- a/packages/interchain/interchain-mock/Cargo.toml +++ b/packages/interchain/interchain-mock/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-mock" -version = "0.5.0" +version = "0.6.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/packages/interchain/proto/Cargo.toml b/packages/interchain/proto/Cargo.toml index d4f722008..01149e1aa 100644 --- a/packages/interchain/proto/Cargo.toml +++ b/packages/interchain/proto/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cw-orch-proto" description = "A helper crate for interaction with protos from different chains. Mostly used for handling cw20 coins and ibc transfers" -version = "0.5.0" +version = "0.6.0" authors.workspace = true edition.workspace = true license.workspace = true From 0088106c9171455db62379befeed645f8c4bd44b Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 18 Sep 2024 13:52:42 +0000 Subject: [PATCH 3/6] Addedclone to interchain env --- packages/interchain/interchain-core/src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/interchain/interchain-core/src/env.rs b/packages/interchain/interchain-core/src/env.rs index e831ae55a..fff1edf4a 100644 --- a/packages/interchain/interchain-core/src/env.rs +++ b/packages/interchain/interchain-core/src/env.rs @@ -109,7 +109,7 @@ pub type ChainId<'a> = &'a str; /// // This makes sure that the packets arrive successfully and present a success ack /// let result = interchain.await_and_check_packets("juno-1", tx_resp).unwrap(); /// ``` -pub trait InterchainEnv { +pub trait InterchainEnv: Clone { /// Type returned by the internal channel creation function /// Examples /// Daemon : This is empty, because hermes doesn't return anything after channel creation From 98e66b3fd17aa768f2d174239d5784e3ee1a1ef8 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 18 Sep 2024 13:37:59 +0000 Subject: [PATCH 4/6] Merge --- .../interchain/interchain-daemon/src/interchain_env.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/interchain/interchain-daemon/src/interchain_env.rs b/packages/interchain/interchain-daemon/src/interchain_env.rs index 0317b559a..a4753f07f 100644 --- a/packages/interchain/interchain-daemon/src/interchain_env.rs +++ b/packages/interchain/interchain-daemon/src/interchain_env.rs @@ -46,7 +46,7 @@ impl DaemonInterchain { /// For use with starship, we advise to use [`cw_orch_starship::Starship::interchain_env`] instead /// channel_creator allows you to specify an object that is able to create channels /// Use [`crate::ChannelCreationValidator`] for manual channel creations. - pub fn new(chains: Vec<(T, Option)>, channel_creator: &C) -> IcDaemonResult + pub fn new(chains: Vec, channel_creator: &C) -> IcDaemonResult where T: Into, { @@ -59,7 +59,7 @@ impl DaemonInterchain { /// Use [`crate::ChannelCreationValidator`] for manual channel creations. /// runtime allows you to control the async runtime (for advanced devs) pub fn new_with_runtime( - chains: Vec<(T, Option)>, + chains: Vec, channel_creator: &C, runtime: &Handle, ) -> IcDaemonResult @@ -69,8 +69,8 @@ impl DaemonInterchain { let mut env = Self::raw(runtime, channel_creator); // We create daemons for each chains - for (chain_data, mnemonic) in chains { - env.build_daemon(runtime, chain_data.into(), mnemonic)?; + for chain_data in chains { + env.build_daemon(runtime, chain_data.into(), None::)?; } Ok(env) From c616ca1b4518c9f599a3ed749f55f3ce4357c7c1 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Tue, 24 Sep 2024 12:59:51 +0000 Subject: [PATCH 5/6] Changged accessor to iterator --- packages/interchain/interchain-core/src/env.rs | 6 ++++-- .../interchain/interchain-daemon/src/interchain_env.rs | 8 +++++--- packages/interchain/interchain-mock/src/interchain.rs | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/interchain/interchain-core/src/env.rs b/packages/interchain/interchain-core/src/env.rs index fff1edf4a..a4f1b3b27 100644 --- a/packages/interchain/interchain-core/src/env.rs +++ b/packages/interchain/interchain-core/src/env.rs @@ -146,10 +146,12 @@ pub trait InterchainEnv: Clone { /// use counter_contract::CounterContract; /// let interchain = MockBech32InterchainEnv::new(vec![("osmosis-1","osmo"),("archway-1","arch")]); /// - /// let all_chains = interchain.chains().unwrap(); + /// let all_chains: Vec<&MockBeck32> = interchain.chains().collect(); /// /// ``` - fn chains(&self) -> Result, Self::Error>; + fn chains<'a>(&'a self) -> impl Iterator + where + Chain: 'a; /// This triggers channel creation between 2 chains /// Returns a channel creation receipt as well as as the connection_id on the src_chain side diff --git a/packages/interchain/interchain-daemon/src/interchain_env.rs b/packages/interchain/interchain-daemon/src/interchain_env.rs index a4753f07f..f4d35171b 100644 --- a/packages/interchain/interchain-daemon/src/interchain_env.rs +++ b/packages/interchain/interchain-daemon/src/interchain_env.rs @@ -287,9 +287,11 @@ impl InterchainEnv for DaemonInterchain { Ok(ibc_trail) } - - fn chains(&self) -> Result, Self::Error> { - Ok(self.daemons.values().cloned().collect()) + fn chains<'a>(&'a self) -> impl Iterator + where + Daemon: 'a, + { + self.daemons.values() } } diff --git a/packages/interchain/interchain-mock/src/interchain.rs b/packages/interchain/interchain-mock/src/interchain.rs index cc3ec8584..87a80b54d 100644 --- a/packages/interchain/interchain-mock/src/interchain.rs +++ b/packages/interchain/interchain-mock/src/interchain.rs @@ -359,8 +359,11 @@ impl InterchainEnv> for MockInterchainEnvBase { Ok(analysis_result) } - fn chains(&self) -> Result>, Self::Error> { - Ok(self.mocks.values().cloned().collect()) + fn chains<'a>(&'a self) -> impl Iterator> + where + MockBase: 'a, + { + self.mocks.values() } } From dd901340cd7d5b24baed0b21e47a2e9711d38242 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Tue, 24 Sep 2024 13:06:41 +0000 Subject: [PATCH 6/6] Version bumps --- packages/interchain/interchain-core/Cargo.toml | 2 +- packages/interchain/interchain-daemon/Cargo.toml | 2 +- packages/interchain/interchain-mock/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/interchain/interchain-core/Cargo.toml b/packages/interchain/interchain-core/Cargo.toml index eacca7184..1cf68804c 100644 --- a/packages/interchain/interchain-core/Cargo.toml +++ b/packages/interchain/interchain-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-core" -version = "0.6.0" +version = "0.6.1" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/packages/interchain/interchain-daemon/Cargo.toml b/packages/interchain/interchain-daemon/Cargo.toml index 69d14b4d2..71271f249 100644 --- a/packages/interchain/interchain-daemon/Cargo.toml +++ b/packages/interchain/interchain-daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-daemon" -version = "0.6.0" +version = "0.6.1" description = "An interchain intergration crate for interacting with actual chain nodes (via gRPC)" authors.workspace = true edition.workspace = true diff --git a/packages/interchain/interchain-mock/Cargo.toml b/packages/interchain/interchain-mock/Cargo.toml index 6c1fc899f..ba3e84b76 100644 --- a/packages/interchain/interchain-mock/Cargo.toml +++ b/packages/interchain/interchain-mock/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-orch-interchain-mock" -version = "0.6.0" +version = "0.6.1" authors.workspace = true edition.workspace = true license.workspace = true