use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
use cosmwasm_std::Addr;
use cw0::{Expiration, NativeBalance};
use cw_storage_plus::Map;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Default, Copy)]
pub struct Permissions {
pub delegate: bool,
pub redelegate: bool,
pub undelegate: bool,
pub withdraw: bool,
}
impl fmt::Display for Permissions {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"staking: {{ delegate: {}, redelegate: {}, undelegate: {}, withdraw: {} }}",
self.delegate, self.redelegate, self.undelegate, self.withdraw
)
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Default)]
pub struct Allowance {
pub balance: NativeBalance,
pub expires: Expiration,
}
#[cfg(test)]
impl Allowance {
pub fn canonical(mut self) -> Self {
self.balance.normalize();
self
}
}
pub const PERMISSIONS: Map<&Addr, Permissions> = Map::new("permissions");
pub const ALLOWANCES: Map<&Addr, Allowance> = Map::new("allowances");