Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even better API for InterchainEnv #492

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,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)

Expand Down
2 changes: 1 addition & 1 deletion cw-orch-interchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
6 changes: 2 additions & 4 deletions cw-orch-interchain/examples/doc_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use cw_orch_interchain::{
fn create_daemon_env() -> cw_orch::anyhow::Result<DaemonInterchain> {
// 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")?;
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-interchain/examples/follow_packets_txhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;

Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/interchain-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion packages/interchain/interchain-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chain: IbcQueryHandler> {
pub trait InterchainEnv<Chain: IbcQueryHandler>: Clone {
/// Type returned by the internal channel creation function
/// Examples
/// Daemon : This is empty, because hermes doesn't return anything after channel creation
Expand Down Expand Up @@ -138,6 +138,19 @@ pub trait InterchainEnv<Chain: IbcQueryHandler> {
/// ```
fn get_chain(&self, chain_id: impl ToString) -> Result<Chain, Self::Error>;

/// 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<Vec<Chain>, Self::Error>;

Kayanski marked this conversation as resolved.
Show resolved Hide resolved
/// 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<Chain>::create_channel] function
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/interchain-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 8 additions & 6 deletions packages/interchain/interchain-daemon/src/interchain_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ pub struct DaemonInterchain<C: ChannelCreator = ChannelCreationValidator> {
rt_handle: Handle,
}

type Mnemonic = String;

impl<C: ChannelCreator> DaemonInterchain<C> {
/// Builds a new [`DaemonInterchain`] instance.
/// 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<T>(chains: Vec<(T, Option<Mnemonic>)>, channel_creator: &C) -> IcDaemonResult<Self>
pub fn new<T>(chains: Vec<T>, channel_creator: &C) -> IcDaemonResult<Self>
where
T: Into<ChainInfoOwned>,
{
Expand All @@ -61,7 +59,7 @@ impl<C: ChannelCreator> DaemonInterchain<C> {
/// Use [`crate::ChannelCreationValidator`] for manual channel creations.
/// runtime allows you to control the async runtime (for advanced devs)
pub fn new_with_runtime<T>(
chains: Vec<(T, Option<Mnemonic>)>,
chains: Vec<T>,
channel_creator: &C,
runtime: &Handle,
) -> IcDaemonResult<Self>
Expand All @@ -71,8 +69,8 @@ impl<C: ChannelCreator> DaemonInterchain<C> {
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::<String>)?;
}

Ok(env)
Expand Down Expand Up @@ -289,6 +287,10 @@ impl<C: ChannelCreator> InterchainEnv<Daemon> for DaemonInterchain<C> {

Ok(ibc_trail)
}

fn chains(&self) -> Result<Vec<Daemon>, Self::Error> {
Ok(self.daemons.values().cloned().collect())
}
}

impl<C: ChannelCreator> DaemonInterchain<C> {
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/interchain-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/interchain/interchain-mock/src/interchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ impl<A: Api> InterchainEnv<MockBase<A>> for MockInterchainEnvBase<A> {

Ok(analysis_result)
}

fn chains(&self) -> Result<Vec<MockBase<A>>, Self::Error> {
Ok(self.mocks.values().cloned().collect())
}
}

fn get_events(tx: &AppResponse, event: &str) -> Vec<Event> {
Expand Down
2 changes: 1 addition & 1 deletion packages/interchain/proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading