use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
use miden_protocol::account::{AccountComponent, AccountComponentName, AccountProcedureRoot};
use crate::account::account_component_code;
use crate::procedure_root;
account_component_code!(
OWNER_ONLY_MINT_POLICY_CODE,
"faucets/policies/mint/owner_controlled/owner_only.masl"
);
procedure_root!(
OWNER_ONLY_POLICY_ROOT,
MintOwnerOnly::NAME,
MintOwnerOnly::PROC_NAME,
MintOwnerOnly::code()
);
#[derive(Debug, Clone, Copy, Default)]
pub struct MintOwnerOnly;
impl MintOwnerOnly {
pub const NAME: &'static str =
"miden::standards::components::faucets::policies::mint::owner_controlled::owner_only";
pub(crate) const PROC_NAME: &str = "check_policy";
pub const fn name() -> AccountComponentName {
AccountComponentName::from_static_str(Self::NAME)
}
pub fn code() -> &'static AccountComponentCode {
&OWNER_ONLY_MINT_POLICY_CODE
}
pub fn root() -> AccountProcedureRoot {
*OWNER_ONLY_POLICY_ROOT
}
}
impl From<MintOwnerOnly> for AccountComponent {
fn from(_: MintOwnerOnly) -> Self {
let metadata = AccountComponentMetadata::new(MintOwnerOnly::NAME).with_description(
"`owner_only` mint policy (owner-controlled family) for fungible faucets",
);
AccountComponent::new(MintOwnerOnly::code().clone(), vec![], metadata).expect(
"`owner_only` mint policy component should satisfy the requirements of a valid account component",
)
}
}