miden_standards/account/access/pausable/manager.rs
1use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
2use miden_protocol::account::{AccountComponent, AccountProcedureRoot};
3
4use crate::account::account_component_code;
5use crate::procedure_root;
6
7// PAUSABLE MANAGER COMPONENT
8// ================================================================================================
9
10account_component_code!(PAUSABLE_MANAGER_CODE, "miden-standards-access-pausable-manager.masp");
11
12// PROCEDURE ROOTS
13// ================================================================================================
14
15/// MASL library namespace used for procedure-root lookups. Distinct from
16/// [`PausableManager::NAME`], which mirrors the standards-side MASM module path.
17const PAUSABLE_MANAGER_LIBRARY_PATH: &str =
18 "miden::standards::components::access::pausable::manager";
19
20procedure_root!(
21 PAUSABLE_MANAGER_PAUSE,
22 PAUSABLE_MANAGER_LIBRARY_PATH,
23 PausableManager::PAUSE_PROC_NAME,
24 PausableManager::code()
25);
26
27procedure_root!(
28 PAUSABLE_MANAGER_UNPAUSE,
29 PAUSABLE_MANAGER_LIBRARY_PATH,
30 PausableManager::UNPAUSE_PROC_NAME,
31 PausableManager::code()
32);
33
34/// Account component exposing `pause` and `unpause` admin procedures, gated by the account-wide
35/// [`crate::account::access::Authority`] component via `exec.authority::assert_authorized`.
36///
37/// `PausableManager` works uniformly with every standard access scheme:
38/// - [`crate::account::access::Authority::AuthControlled`] — installed directly by the user-account
39/// faucet factories (e.g. [`crate::account::faucets::create_singlesig_user_fungible_faucet`]);
40/// gates pause / unpause via the account's own auth component.
41/// - [`crate::account::access::AccessControl::Ownable2Step`] →
42/// [`crate::account::access::Authority::OwnerControlled`] requires the Ownable2Step owner.
43/// - [`crate::account::access::AccessControl::Rbac`] →
44/// [`crate::account::access::Authority::RbacControlled`] for roles per procedure.
45///
46/// Companion components required:
47/// - [`crate::account::access::Authority`] — installed automatically by the
48/// [`crate::account::access::AccessControl`] enum (or directly by user-faucet factories).
49/// - [`super::Pausable`] — provides the `is_paused` storage slot that pause / unpause write to.
50#[derive(Debug, Clone, Copy, Default)]
51pub struct PausableManager;
52
53impl PausableManager {
54 /// The name of the component.
55 pub const NAME: &'static str = "miden::standards::access::pausable::manager";
56
57 const PAUSE_PROC_NAME: &'static str = "pause";
58 const UNPAUSE_PROC_NAME: &'static str = "unpause";
59
60 /// Returns the [`AccountComponentCode`] of this component.
61 pub fn code() -> &'static AccountComponentCode {
62 &PAUSABLE_MANAGER_CODE
63 }
64
65 /// Returns the procedure root of the `pause` procedure exposed by this component.
66 pub fn pause_root() -> AccountProcedureRoot {
67 *PAUSABLE_MANAGER_PAUSE
68 }
69
70 /// Returns the procedure root of the `unpause` procedure exposed by this component.
71 pub fn unpause_root() -> AccountProcedureRoot {
72 *PAUSABLE_MANAGER_UNPAUSE
73 }
74}
75
76impl From<PausableManager> for AccountComponent {
77 fn from(_: PausableManager) -> Self {
78 let metadata = AccountComponentMetadata::new(PausableManager::NAME).with_description(
79 "PausableManager: pause / unpause admin procedures gated by the account-wide \
80 Authority component. Requires the Pausable companion component for storage and the \
81 Authority component for auth dispatch.",
82 );
83
84 AccountComponent::new(PausableManager::code().clone(), vec![], metadata).expect(
85 "pausable manager component should satisfy the requirements of a valid account component",
86 )
87 }
88}