use crate::features::ModuleIdentification;
use crate::{base::Handler, AbstractSdkError};
use abstract_std::ibc::ModuleIbcMsg;
use cosmwasm_std::{Addr, Deps, DepsMut, Env, MessageInfo, Response};
pub trait ModuleIbcEndpoint: Handler {
fn ibc_host(&self, deps: Deps) -> Result<Addr, Self::Error>;
fn module_ibc(
self,
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ModuleIbcMsg,
) -> Result<Response, Self::Error> {
let ibc_host = self.ibc_host(deps.as_ref())?;
if info.sender.ne(&ibc_host) {
return Err(AbstractSdkError::ModuleIbcNotCalledByHost {
caller: info.sender,
host_addr: ibc_host,
module: self.info().0.to_string(),
}
.into());
};
let handler =
self.maybe_module_ibc_handler()
.ok_or(AbstractSdkError::NoModuleIbcHandler(
self.module_id().to_string(),
))?;
handler(deps, env, self, msg.src_module_info, msg.msg)
}
}