abstract_ibc_host/
contract.rs1use abstract_macros::abstract_response;
2use abstract_sdk::std::ibc_host::{InstantiateMsg, QueryMsg};
3use abstract_std::{
4 ibc_host::{ExecuteMsg, MigrateMsg},
5 objects::module_version::{assert_cw_contract_upgrade, migrate_module_data},
6 IBC_HOST,
7};
8use cosmwasm_std::{
9 Binary, Deps, DepsMut, Env, IbcReceiveResponse, MessageInfo, Reply, Response, StdError,
10};
11use semver::Version;
12
13use crate::{
14 endpoints::{
15 self,
16 reply::{
17 reply_execute_action, reply_forward_response_data, INIT_BEFORE_ACTION_REPLY_ID,
18 RESPONSE_REPLY_ID,
19 },
20 },
21 error::HostError,
22};
23
24pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
25
26#[abstract_response(IBC_HOST)]
27pub struct HostResponse;
28
29pub type HostResult<T = Response> = Result<T, HostError>;
30pub type IbcHostResult = HostResult<IbcReceiveResponse>;
31
32#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
33pub fn instantiate(deps: DepsMut, env: Env, info: MessageInfo, msg: InstantiateMsg) -> HostResult {
34 endpoints::instantiate(deps, env, info, msg)
35}
36
37#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
38pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> HostResult {
39 endpoints::execute(deps, env, info, msg)
41}
42
43#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
44pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> HostResult<Binary> {
45 endpoints::query(deps, env, msg)
47}
48
49#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
50pub fn reply(deps: DepsMut, env: Env, reply_msg: Reply) -> HostResult {
51 if reply_msg.id == INIT_BEFORE_ACTION_REPLY_ID {
52 reply_execute_action(deps, env, reply_msg)
53 } else if reply_msg.id == RESPONSE_REPLY_ID {
54 reply_forward_response_data(reply_msg)
55 } else {
56 Err(HostError::Std(StdError::generic_err("Not implemented")))
57 }
58}
59
60#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
61pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> HostResult {
62 let to_version: Version = CONTRACT_VERSION.parse().unwrap();
63
64 assert_cw_contract_upgrade(deps.storage, IBC_HOST, to_version)?;
65 cw2::set_contract_version(deps.storage, IBC_HOST, CONTRACT_VERSION)?;
66 migrate_module_data(deps.storage, IBC_HOST, CONTRACT_VERSION, None::<String>)?;
67 Ok(HostResponse::action("migrate"))
68}