use steel::*;
use crate::{
consts::*,
state::{Config, Metrics, Snapshot, Treasury},
};
pub trait MiracleAccountInfoValidation {
fn is_config(&self) -> Result<&Self, ProgramError>;
fn is_treasury(&self) -> Result<&Self, ProgramError>;
fn is_treasury_tokens(&self) -> Result<&Self, ProgramError>;
fn is_snapshot(&self) -> Result<&Self, ProgramError>;
fn is_metrics(&self) -> Result<&Self, ProgramError>;
}
impl MiracleAccountInfoValidation for AccountInfo<'_> {
fn is_config(&self) -> Result<&Self, ProgramError> {
self.has_address(&CONFIG_ADDRESS)?
.is_type::<Config>(&crate::ID)
}
fn is_treasury(&self) -> Result<&Self, ProgramError> {
self.has_address(&TREASURY_ADDRESS)?
.is_type::<Treasury>(&crate::ID)
}
fn is_treasury_tokens(&self) -> Result<&Self, ProgramError> {
self.has_address(&TREASURY_TOKENS_ADDRESS)
}
fn is_snapshot(&self) -> Result<&Self, ProgramError> {
self.has_address(&SNAPSHOT_ADDRESS)?
.is_type::<Snapshot>(&crate::ID)
}
fn is_metrics(&self) -> Result<&Self, ProgramError> {
self.has_address(&METRICS_ADDRESS)?
.is_type::<Metrics>(&crate::ID)
}
}