use crate::{
base::{
ExecuteMsg as MiddlewareExecMsg, InstantiateMsg as MiddlewareInstantiateMsg,
MigrateMsg as MiddlewareMigrateMsg, QueryMsg as MiddlewareQueryMsg,
},
ibc_client::CallbackInfo,
objects::core::AccountId,
};
use cosmwasm_schema::QueryResponses;
use cosmwasm_std::{Addr, Binary, CosmosMsg, Empty, QueryRequest};
pub type ExecuteMsg<T, R = Empty> = MiddlewareExecMsg<BaseExecuteMsg, T, R>;
pub type QueryMsg<T = Empty> = MiddlewareQueryMsg<BaseQueryMsg, T>;
pub type InstantiateMsg<T = Empty> = MiddlewareInstantiateMsg<BaseInstantiateMsg, T>;
pub type MigrateMsg<T = Empty> = MiddlewareMigrateMsg<BaseMigrateMsg, T>;
#[cosmwasm_schema::cw_serde]
pub struct BaseInstantiateMsg {
pub ans_host_address: String,
pub cw1_code_id: u64,
}
#[cosmwasm_schema::cw_serde]
pub struct BaseMigrateMsg {}
#[cosmwasm_schema::cw_serde]
pub enum InternalAction {
Register { account_proxy_address: String },
WhoAmI,
}
#[cosmwasm_schema::cw_serde]
pub enum HostAction {
App {
msg: Binary,
},
Dispatch {
msgs: Vec<CosmosMsg<Empty>>,
},
Query {
msgs: Vec<QueryRequest<Empty>>,
},
SendAllBack {},
Balances {},
Internal(InternalAction),
}
impl HostAction {
pub fn into_packet(
self,
account_id: AccountId,
retries: u8,
client_chain: String,
callback_info: Option<CallbackInfo>,
) -> PacketMsg {
PacketMsg {
client_chain,
retries,
callback_info,
account_id,
action: self,
}
}
}
#[cosmwasm_schema::cw_serde]
pub struct PacketMsg {
pub client_chain: String,
pub retries: u8,
pub account_id: AccountId,
pub callback_info: Option<CallbackInfo>,
pub action: HostAction,
}
#[cosmwasm_schema::cw_serde]
pub enum BaseExecuteMsg {
UpdateAdmin { admin: String },
UpdateConfig {
ans_host_address: Option<String>,
cw1_code_id: Option<u64>,
},
RecoverAccount {
closed_channel: String,
account_id: AccountId,
msgs: Vec<CosmosMsg>,
},
}
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses)]
pub enum BaseQueryMsg {
#[returns(HostConfigResponse)]
Config {},
#[returns(AccountResponse)]
Account {
client_chain: String,
account_id: AccountId,
},
#[returns(ListAccountsResponse)]
ListAccounts {},
}
#[cosmwasm_schema::cw_serde]
pub struct HostConfigResponse {
pub ans_host_address: Addr,
}
#[cosmwasm_schema::cw_serde]
pub struct AccountResponse {
pub account: Option<String>,
}
#[cosmwasm_schema::cw_serde]
pub struct ListAccountsResponse {
pub accounts: Vec<AccountInfo>,
}
#[cosmwasm_schema::cw_serde]
pub struct AccountInfo {
pub account_id: AccountId,
pub account: String,
pub channel_id: String,
}