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
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(BlocklistStorage);
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(BlocklistStorage::with_blocked_accounts(blocked_accounts))
61 }
62
63 pub fn blocked_accounts(&self) -> &BTreeSet<AccountId> {
65 self.0.blocked_accounts()
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<BlocklistStorage> for BasicBlocklist {
80 fn from(storage: BlocklistStorage) -> Self {
81 Self(storage)
82 }
83}
84
85impl From<BasicBlocklist> for AccountComponent {
86 fn from(blocklist: BasicBlocklist) -> Self {
87 let storage_schema = StorageSchema::new([BlocklistStorage::blocked_accounts_slot_schema()])
88 .expect("storage schema should be valid");
89
90 let metadata = AccountComponentMetadata::new(BasicBlocklist::NAME)
91 .with_description(
92 "Basic blocklist transfer policy: predicate procedure plus the `blocked_accounts` \
93 storage map it reads",
94 )
95 .with_storage_schema(storage_schema);
96
97 AccountComponent::new(BasicBlocklist::code().clone(), vec![blocklist.0.into_slot()], metadata)
98 .expect(
99 "basic blocklist transfer policy component should satisfy the requirements of a valid account component",
100 )
101 }
102}