use crate::{
AbstractContract, AppError, ExecuteHandlerFn, IbcCallbackHandlerFn, InstantiateHandlerFn,
MigrateHandlerFn, QueryHandlerFn, ReceiveHandlerFn, ReplyHandlerFn,
};
use abstract_core::objects::dependency::StaticDependency;
use abstract_sdk::{
base::SudoHandlerFn,
feature_objects::AnsHost,
namespaces::{ADMIN_NAMESPACE, BASE_STATE},
AbstractSdkError,
};
use cosmwasm_std::{Addr, Empty, StdResult, Storage};
use cw_controllers::Admin;
use cw_storage_plus::Item;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub trait ContractError:
From<cosmwasm_std::StdError> + From<AppError> + From<AbstractSdkError> + 'static
{
}
impl<T> ContractError for T where
T: From<cosmwasm_std::StdError> + From<AppError> + From<AbstractSdkError> + 'static
{
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct AppState {
pub proxy_address: Addr,
pub ans_host: AnsHost,
}
pub struct AppContract<
Error: ContractError,
CustomInitMsg: 'static,
CustomExecMsg: 'static,
CustomQueryMsg: 'static,
CustomMigrateMsg: 'static,
Receive: 'static = Empty,
SudoMsg: 'static = Empty,
> {
pub admin: Admin<'static>,
pub(crate) base_state: Item<'static, AppState>,
pub(crate) contract: AbstractContract<Self, Error>,
}
impl<
Error: ContractError,
CustomInitMsg,
CustomExecMsg,
CustomQueryMsg,
CustomMigrateMsg,
ReceiveMsg,
SudoMsg,
>
AppContract<
Error,
CustomInitMsg,
CustomExecMsg,
CustomQueryMsg,
CustomMigrateMsg,
ReceiveMsg,
SudoMsg,
>
{
pub const fn new(
name: &'static str,
version: &'static str,
metadata: Option<&'static str>,
) -> Self {
Self {
base_state: Item::new(BASE_STATE),
admin: Admin::new(ADMIN_NAMESPACE),
contract: AbstractContract::new(name, version, metadata),
}
}
pub fn load_state(&self, store: &dyn Storage) -> StdResult<AppState> {
self.base_state.load(store)
}
pub const fn with_dependencies(mut self, dependencies: &'static [StaticDependency]) -> Self {
self.contract = self.contract.with_dependencies(dependencies);
self
}
pub const fn with_instantiate(
mut self,
instantiate_handler: InstantiateHandlerFn<Self, CustomInitMsg, Error>,
) -> Self {
self.contract = self.contract.with_instantiate(instantiate_handler);
self
}
pub const fn with_execute(
mut self,
execute_handler: ExecuteHandlerFn<Self, CustomExecMsg, Error>,
) -> Self {
self.contract = self.contract.with_execute(execute_handler);
self
}
pub const fn with_query(
mut self,
query_handler: QueryHandlerFn<Self, CustomQueryMsg, Error>,
) -> Self {
self.contract = self.contract.with_query(query_handler);
self
}
pub const fn with_migrate(
mut self,
migrate_handler: MigrateHandlerFn<Self, CustomMigrateMsg, Error>,
) -> Self {
self.contract = self.contract.with_migrate(migrate_handler);
self
}
pub const fn with_replies(
mut self,
reply_handlers: &'static [(u64, ReplyHandlerFn<Self, Error>)],
) -> Self {
self.contract = self.contract.with_replies([&[], reply_handlers]);
self
}
pub const fn with_sudo(mut self, sudo_handler: SudoHandlerFn<Self, SudoMsg, Error>) -> Self {
self.contract = self.contract.with_sudo(sudo_handler);
self
}
pub const fn with_receive(
mut self,
receive_handler: ReceiveHandlerFn<Self, ReceiveMsg, Error>,
) -> Self {
self.contract = self.contract.with_receive(receive_handler);
self
}
pub const fn with_ibc_callbacks(
mut self,
callbacks: &'static [(&'static str, IbcCallbackHandlerFn<Self, Error>)],
) -> Self {
self.contract = self.contract.with_ibc_callbacks(callbacks);
self
}
}