diff --git a/cosmwasm/ucs00-pingpong/src/ibc.rs b/cosmwasm/ucs00-pingpong/src/ibc.rs index 3b8ee51ee8..83e98082ab 100644 --- a/cosmwasm/ucs00-pingpong/src/ibc.rs +++ b/cosmwasm/ucs00-pingpong/src/ibc.rs @@ -1,7 +1,9 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; use cosmwasm_std::{ - attr, entry_point, DepsMut, Env, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, - IbcChannelConnectMsg, IbcChannelOpenMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, Reply, Response, StdError, + attr, DepsMut, Env, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, + IbcChannelOpenMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg, + IbcPacketTimeoutMsg, IbcReceiveResponse, Reply, Response, StdError, }; use crate::{msg::UCS00PingPong, state::CONFIG, ContractError}; diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index c3fa78474f..fbba9c3e79 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -13,7 +13,6 @@ use crate::{ ChainId, ClientInfo, ClientStateMeta, ClientType, ConsensusStateMeta, IbcInterface, IbcSpec, }, data::Data, - rpc::ProofType, RawClientId, VoyagerMessage, }; @@ -82,10 +81,10 @@ pub struct ConsensusModuleInfo { pub chain_id: ChainId, #[arg(value_parser(|s: &str| ok(ConsensusType::new(s.to_owned()))))] pub consensus_type: ConsensusType, - // REVIEW: Maybe we need this? Do different client types for a single consensus necessarily - // have the same client and consensus state types? /// The type of client this consensus - // module provides state for. #[arg(value_parser(|s: &str| - // ok(ClientType::new(s.to_owned()))))] pub client_type: ClientType, + // REVIEW: Maybe we need this? Do different client types for a single consensus necessarily have the same client and consensus state types? + // /// The type of client this consensus module provides state for. + // #[arg(value_parser(|s: &str| ok(ClientType::new(s.to_owned()))))] + // pub client_type: ClientType, } impl ConsensusModuleInfo { @@ -177,12 +176,20 @@ impl ClientModuleInfo { pub fn ensure_ibc_interface( &self, - ibc_interface: impl AsRef, + expected_interfaces: impl IntoIterator, ) -> Result<(), UnexpectedIbcInterfaceError> { - if ibc_interface.as_ref() != self.ibc_interface.as_str() { + let expected_interfaces: Vec = expected_interfaces + .into_iter() + .map(IbcInterface::new) + .collect(); + + if !expected_interfaces + .iter() + .any(|e| e.as_str() == self.ibc_interface.as_str()) + { Err(UnexpectedIbcInterfaceError { - expected: self.ibc_interface.clone(), - found: ibc_interface.as_ref().to_owned(), + expected: expected_interfaces, + found: self.ibc_interface.to_string(), }) } else { Ok(()) @@ -256,36 +263,28 @@ pub struct UnexpectedChainIdError { } #[derive(Debug, Clone, thiserror::Error)] -#[error( - "invalid consensus type: this module provides functionality for consensus type `{expected}`, but the config specifies `{found}`" -)] +#[error("invalid consensus type: this module provides functionality for consensus type `{expected}`, but the config specifies `{found}`")] pub struct UnexpectedConsensusTypeError { pub expected: ConsensusType, pub found: String, } #[derive(Debug, Clone, thiserror::Error)] -#[error( - "invalid client type: this module provides functionality for client type `{expected}`, but the config specifies `{found}`" -)] +#[error("invalid client type: this module provides functionality for client type `{expected}`, but the config specifies `{found}`")] pub struct UnexpectedClientTypeError { pub expected: ClientType, pub found: String, } #[derive(Debug, Clone, thiserror::Error)] -#[error( - "invalid IBC interface: this module provides functionality for IBC interface `{expected}`, but the config specifies `{found}`" -)] +#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`", expected = expected.iter().map(|x| x.as_str()).collect::>().join(","))] pub struct UnexpectedIbcInterfaceError { - pub expected: IbcInterface, + pub expected: Vec, pub found: String, } #[derive(Debug, Clone, thiserror::Error)] -#[error( - "invalid IBC version: this module provides functionality for IBC version `{expected}`, but the config specifies `{found}`" -)] +#[error("invalid IBC version: this module provides functionality for IBC version `{expected}`, but the config specifies `{found}`")] pub struct UnexpectedIbcVersionIdError { pub expected: IbcSpecId, pub found: String, @@ -359,18 +358,14 @@ pub trait ProofModule { /// Query a proof of IBC state on this chain, at the specified [`Height`], /// returning the state as a JSON [`Value`]. #[method(name = "queryIbcProof", with_extensions)] - async fn query_ibc_proof( - &self, - at: Height, - path: V::StorePath, - ) -> RpcResult<(Value, ProofType)>; + async fn query_ibc_proof(&self, at: Height, path: V::StorePath) -> RpcResult; } /// Type-erased version of [`ProofModuleClient`]. #[rpc(client, namespace = "proof")] pub trait RawProofModule { #[method(name = "queryIbcProof")] - async fn query_ibc_proof_raw(&self, at: Height, path: Value) -> RpcResult<(Value, ProofType)>; + async fn query_ibc_proof_raw(&self, at: Height, path: Value) -> RpcResult; } /// Client modules provide functionality to interact with a single light client @@ -431,9 +426,7 @@ pub trait ConsensusModule { async fn query_latest_timestamp(&self, finalized: bool) -> RpcResult; } -/// Client bootstrap modules provide the initial client and consensus states for a client. This is -/// notably separate from the [`ConsensusModule`], since it is possible for different client types -/// (with different state types) to track the same consensus. +/// Client bootstrap modules provide the initial client and consensus states for a client. This is notably separate from the [`ConsensusModule`], since it is possible for different client types (with different state types) to track the same consensus. #[rpc(client, server, namespace = "clientBootstrap")] pub trait ClientBootstrapModule { /// The client state of this chain at the specified [`Height`]. diff --git a/voyager/modules/client/ethereum/src/main.rs b/voyager/modules/client/ethereum/src/main.rs index 6137dcb0d8..91c7f400ac 100644 --- a/voyager/modules/client/ethereum/src/main.rs +++ b/voyager/modules/client/ethereum/src/main.rs @@ -47,7 +47,7 @@ impl ClientModule for Module { async fn new(config: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::ETHEREUM)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM)?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Self { chain_spec: config.chain_spec, diff --git a/voyager/modules/client/movement/src/main.rs b/voyager/modules/client/movement/src/main.rs index bcda88e776..d231ffd50f 100644 --- a/voyager/modules/client/movement/src/main.rs +++ b/voyager/modules/client/movement/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(Config {}: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::MOVEMENT)?; info.ensure_consensus_type(ConsensusType::MOVEMENT)?; - info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM)?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Module {}) } diff --git a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs index 43bf9933f7..d0424bb19a 100644 --- a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_ICS23)?; info.ensure_consensus_type(ConsensusType::TENDERMINT)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY)?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Self {}) } } diff --git a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs index 788819f486..31f8753d9c 100644 --- a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs @@ -85,9 +85,11 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_MPT)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY) - .or(info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM)) - .or(info.ensure_ibc_interface(IbcInterface::IBC_MOVE_APTOS))?; + info.ensure_ibc_interface([ + IbcInterface::IBC_SOLIDITY, + IbcInterface::IBC_COSMWASM, + IbcInterface::IBC_MOVE_APTOS, + ])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?, diff --git a/voyager/modules/client/state-lens/ics23-smt/src/main.rs b/voyager/modules/client/state-lens/ics23-smt/src/main.rs index ff0323d305..381a091315 100644 --- a/voyager/modules/client/state-lens/ics23-smt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-smt/src/main.rs @@ -81,8 +81,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_SMT)?; info.ensure_consensus_type(ConsensusType::MOVEMENT)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY) - .or(info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM))?; + info.ensure_ibc_interface([IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?,