Skip to main content

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