use std::ops::{Deref, DerefMut};
use abstract_interface::RegisteredModule;
use cw_orch::{contract::Contract, prelude::*};
use crate::{account::Account, client::AbstractClientResult};
pub struct Application<T: CwEnv, M> {
account: Account<T>,
module: M,
}
impl<Chain: CwEnv, M> Deref for Application<Chain, M> {
type Target = M;
fn deref(&self) -> &Self::Target {
&self.module
}
}
impl<Chain: CwEnv, M> DerefMut for Application<Chain, M> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.module
}
}
impl<Chain: CwEnv, M: RegisteredModule> Application<Chain, M> {
pub(crate) fn new(account: Account<Chain>, module: M) -> AbstractClientResult<Self> {
account.module_addresses(vec![M::module_id().to_string()])?;
Ok(Self { account, module })
}
pub fn account(&self) -> &Account<Chain> {
&self.account
}
pub fn module<T: RegisteredModule + From<Contract<Chain>>>(&self) -> AbstractClientResult<T> {
self.account.module()
}
}
impl<Chain: CwEnv, M: ContractInstance<Chain>> Application<Chain, M> {
pub fn authorize_on_adapters(&self, adapter_ids: &[&str]) -> AbstractClientResult<()> {
for module_id in adapter_ids {
self.account
.abstr_account
.manager
.update_adapter_authorized_addresses(module_id, vec![self.addr_str()?], vec![])?;
}
Ok(())
}
}