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 "faucets/policies/transfer/basic_blocklist.masl"
20);
21
22procedure_root!(
23 BASIC_BLOCKLIST_TRANSFER_POLICY_ROOT,
24 BasicBlocklist::NAME,
25 BasicBlocklist::PROC_NAME,
26 BasicBlocklist::code()
27);
28
29#[derive(Debug, Clone, Default)]
46pub struct BasicBlocklist(BTreeSet<AccountId>);
47
48impl BasicBlocklist {
49 pub const NAME: &'static str =
51 "miden::standards::components::faucets::policies::transfer::basic_blocklist";
52
53 pub(crate) const PROC_NAME: &str = "check_policy";
54
55 pub fn with_blocked_accounts<I>(blocked_accounts: I) -> Self
57 where
58 I: IntoIterator<Item = AccountId>,
59 {
60 Self(blocked_accounts.into_iter().collect())
61 }
62
63 pub fn blocked_accounts(&self) -> &BTreeSet<AccountId> {
65 &self.0
66 }
67
68 pub fn code() -> &'static AccountComponentCode {
70 &BASIC_BLOCKLIST_TRANSFER_POLICY_CODE
71 }
72
73 pub fn root() -> AccountProcedureRoot {
75 *BASIC_BLOCKLIST_TRANSFER_POLICY_ROOT
76 }
77}
78
79impl From<BasicBlocklist> for AccountComponent {
80 fn from(blocklist: BasicBlocklist) -> Self {
81 let storage = BlocklistStorage::with_blocked_accounts(blocklist.0);
82 let storage_schema = StorageSchema::new([BlocklistStorage::blocked_accounts_slot_schema()])
83 .expect("storage schema should be valid");
84
85 let metadata = AccountComponentMetadata::new(BasicBlocklist::NAME)
86 .with_description(
87 "Basic blocklist transfer policy: predicate procedure plus the `blocked_accounts` \
88 storage map it reads",
89 )
90 .with_storage_schema(storage_schema);
91
92 AccountComponent::new(BasicBlocklist::code().clone(), vec![storage.into_slot()], metadata)
93 .expect(
94 "basic blocklist transfer policy component should satisfy the requirements of a valid account component",
95 )
96 }
97}