use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
use miden_protocol::account::{AccountComponent, AccountProcedureRoot};
use crate::account::account_component_code;
use crate::procedure_root;
account_component_code!(
ALLOWLIST_MANAGER_CODE,
"miden-standards-faucets-policies-transfer-allowlist-manager.masp"
);
const ALLOWLIST_MANAGER_LIBRARY_PATH: &str =
"miden::standards::components::faucets::policies::transfer::allowlist::manager";
procedure_root!(
ALLOWLIST_MANAGER_ALLOW_ACCOUNT,
ALLOWLIST_MANAGER_LIBRARY_PATH,
AllowlistManager::ALLOW_ACCOUNT_PROC_NAME,
AllowlistManager::code()
);
procedure_root!(
ALLOWLIST_MANAGER_DISALLOW_ACCOUNT,
ALLOWLIST_MANAGER_LIBRARY_PATH,
AllowlistManager::DISALLOW_ACCOUNT_PROC_NAME,
AllowlistManager::code()
);
#[derive(Debug, Clone, Copy, Default)]
pub struct AllowlistManager;
impl AllowlistManager {
pub const NAME: &'static str =
"miden::standards::faucets::policies::transfer::allowlist::manager";
const ALLOW_ACCOUNT_PROC_NAME: &'static str = "allow_account";
const DISALLOW_ACCOUNT_PROC_NAME: &'static str = "disallow_account";
pub fn code() -> &'static AccountComponentCode {
&ALLOWLIST_MANAGER_CODE
}
pub fn allow_account_root() -> AccountProcedureRoot {
*ALLOWLIST_MANAGER_ALLOW_ACCOUNT
}
pub fn disallow_account_root() -> AccountProcedureRoot {
*ALLOWLIST_MANAGER_DISALLOW_ACCOUNT
}
pub fn component_metadata() -> AccountComponentMetadata {
AccountComponentMetadata::new(Self::NAME).with_description(
"Authority-gated allowlist admin: wraps `allowlist::allow_account` / \
`disallow_account` with the account-wide Authority component.",
)
}
}
impl From<AllowlistManager> for AccountComponent {
fn from(_: AllowlistManager) -> Self {
let metadata = AllowlistManager::component_metadata();
AccountComponent::new(AllowlistManager::code().clone(), vec![], metadata)
.expect("authority-gated allowlist admin component should be valid")
}
}