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!(
BLOCKLIST_MANAGER_CODE,
"miden-standards-faucets-policies-transfer-blocklist-manager.masp"
);
const BLOCKLIST_MANAGER_LIBRARY_PATH: &str =
"miden::standards::components::faucets::policies::transfer::blocklist::manager";
procedure_root!(
BLOCKLIST_MANAGER_BLOCK_ACCOUNT,
BLOCKLIST_MANAGER_LIBRARY_PATH,
BlocklistManager::BLOCK_ACCOUNT_PROC_NAME,
BlocklistManager::code()
);
procedure_root!(
BLOCKLIST_MANAGER_UNBLOCK_ACCOUNT,
BLOCKLIST_MANAGER_LIBRARY_PATH,
BlocklistManager::UNBLOCK_ACCOUNT_PROC_NAME,
BlocklistManager::code()
);
#[derive(Debug, Clone, Copy, Default)]
pub struct BlocklistManager;
impl BlocklistManager {
pub const NAME: &'static str =
"miden::standards::faucets::policies::transfer::blocklist::manager";
const BLOCK_ACCOUNT_PROC_NAME: &'static str = "block_account";
const UNBLOCK_ACCOUNT_PROC_NAME: &'static str = "unblock_account";
pub fn code() -> &'static AccountComponentCode {
&BLOCKLIST_MANAGER_CODE
}
pub fn block_account_root() -> AccountProcedureRoot {
*BLOCKLIST_MANAGER_BLOCK_ACCOUNT
}
pub fn unblock_account_root() -> AccountProcedureRoot {
*BLOCKLIST_MANAGER_UNBLOCK_ACCOUNT
}
pub fn component_metadata() -> AccountComponentMetadata {
AccountComponentMetadata::new(Self::NAME).with_description(
"Authority-gated blocklist admin: wraps `blocklist::block_account` / \
`unblock_account` with the account-wide Authority component.",
)
}
}
impl From<BlocklistManager> for AccountComponent {
fn from(_: BlocklistManager) -> Self {
let metadata = BlocklistManager::component_metadata();
AccountComponent::new(BlocklistManager::code().clone(), vec![], metadata)
.expect("authority-gated blocklist admin component should be valid")
}
}