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

refactor(voyager): ensure_ibc_interface supports multiple interfaces #3578

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
8 changes: 5 additions & 3 deletions cosmwasm/ucs00-pingpong/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
20 changes: 14 additions & 6 deletions lib/voyager-message/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,20 @@ impl ClientModuleInfo {

pub fn ensure_ibc_interface(
&self,
ibc_interface: impl AsRef<str>,
expected_interfaces: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<(), UnexpectedIbcInterfaceError> {
if ibc_interface.as_ref() != self.ibc_interface.as_str() {
let expected_interfaces: Vec<String> = expected_interfaces
.into_iter()
.map(|s| s.as_ref().to_string())
.collect();

if !expected_interfaces
.iter()
.any(|expected| expected == 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(())
Expand Down Expand Up @@ -269,9 +277,9 @@ pub struct UnexpectedClientTypeError {
}

#[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}`")]
pub struct UnexpectedIbcInterfaceError {
pub expected: IbcInterface,
pub expected: Vec<String>,
pub found: String,
}

Expand Down
2 changes: 1 addition & 1 deletion voyager/modules/client/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ClientModule for Module {
async fn new(config: Self::Config, info: ClientModuleInfo) -> Result<Self, BoxDynError> {
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,
Expand Down
2 changes: 1 addition & 1 deletion voyager/modules/client/movement/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ClientModule for Module {
async fn new(Config {}: Self::Config, info: ClientModuleInfo) -> Result<Self, BoxDynError> {
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 {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ClientModule for Module {
async fn new(_: Self::Config, info: ClientModuleInfo) -> Result<Self, BoxDynError> {
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 {})
}
}
Expand Down
8 changes: 5 additions & 3 deletions voyager/modules/client/state-lens/ics23-mpt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ impl ClientModule for Module {
async fn new(_: Self::Config, info: ClientModuleInfo) -> Result<Self, BoxDynError> {
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())?,
Expand Down
3 changes: 1 addition & 2 deletions voyager/modules/client/state-lens/ics23-smt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ impl ClientModule for Module {
async fn new(_: Self::Config, info: ClientModuleInfo) -> Result<Self, BoxDynError> {
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())?,
Expand Down