use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::Addr;
use cw_storage_plus::Item;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Config {
pub admins: Vec<Addr>,
pub executors: Vec<Addr>,
}
impl Config {
pub fn is_admin(&self, addr: impl AsRef<str>) -> bool {
let addr = addr.as_ref();
self.admins.iter().any(|a| a.as_ref() == addr)
}
pub fn is_executor(&self, addr: impl AsRef<str>) -> bool {
let addr = addr.as_ref();
self.executors.iter().any(|a| a.as_ref() == addr)
}
pub fn can_modify(&self, addr: &str) -> bool {
self.is_admin(addr)
}
pub fn can_execute(&self, addr: &str) -> bool {
self.is_executor(addr)
}
}
pub const CONFIG_KEY: &str = "config";
pub const CONFIG: Item<Config> = Item::new(CONFIG_KEY);