miden_standards/account/policies/transfer/
basic_blocklist.rs1use alloc::collections::BTreeSet;
2
3use miden_protocol::account::component::{
4 AccountComponentCode,
5 AccountComponentMetadata,
6 StorageSchema,
7};
8use miden_protocol::account::{AccountComponent, AccountId, AccountProcedureRoot};
9
10use crate::account::account_component_code;
11use crate::account::policies::transfer::blocklist::BlocklistStorage;
12use crate::procedure_root;
13
14account_component_code!(
18 BASIC_BLOCKLIST_TRANSFER_POLICY_CODE,
19 "miden-standards-faucets-policies-transfer-basic-blocklist.masp"
20);
21
22const BASIC_BLOCKLIST_LIBRARY_PATH: &str =
28 "miden::standards::components::faucets::policies::transfer::basic_blocklist";
29
30procedure_root!(
31 BASIC_BLOCKLIST_TRANSFER_POLICY_ROOT,
32 BASIC_BLOCKLIST_LIBRARY_PATH,
33 BasicBlocklist::PROC_NAME,
34 BasicBlocklist::code()
35);
36
37#[derive(Debug, Clone, Default)]
56pub struct BasicBlocklist(BlocklistStorage);
57
58impl BasicBlocklist {
59 pub const NAME: &'static str = "miden::standards::faucets::policies::transfer::basic_blocklist";
61
62 pub(crate) const PROC_NAME: &str = "check_policy";
63
64 pub fn with_blocked_accounts<I>(blocked_accounts: I) -> Self
66 where
67 I: IntoIterator<Item = AccountId>,
68 {
69 Self(BlocklistStorage::with_blocked_accounts(blocked_accounts))
70 }
71
72 pub fn blocked_accounts(&self) -> &BTreeSet<AccountId> {
74 self.0.blocked_accounts()
75 }
76
77 pub fn code() -> &'static AccountComponentCode {
79 &BASIC_BLOCKLIST_TRANSFER_POLICY_CODE
80 }
81
82 pub fn root() -> AccountProcedureRoot {
84 *BASIC_BLOCKLIST_TRANSFER_POLICY_ROOT
85 }
86}
87
88impl From<BlocklistStorage> for BasicBlocklist {
89 fn from(storage: BlocklistStorage) -> Self {
90 Self(storage)
91 }
92}
93
94impl From<BasicBlocklist> for AccountComponent {
95 fn from(blocklist: BasicBlocklist) -> Self {
96 let storage_schema = StorageSchema::new([BlocklistStorage::blocked_accounts_slot_schema()])
97 .expect("storage schema should be valid");
98
99 let metadata = AccountComponentMetadata::new(BasicBlocklist::NAME)
100 .with_description(
101 "Basic blocklist transfer policy: predicate procedure plus the `blocked_accounts` \
102 storage map it reads",
103 )
104 .with_storage_schema(storage_schema);
105
106 AccountComponent::new(BasicBlocklist::code().clone(), vec![blocklist.0.into_slot()], metadata)
107 .expect(
108 "basic blocklist transfer policy component should satisfy the requirements of a valid account component",
109 )
110 }
111}