use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
use miden_protocol::account::{AccountComponent, AccountProcedureRoot};
use crate::account::account_component_code;
use crate::procedure_root;
account_component_code!(
ALLOW_ALL_TRANSFER_POLICY_CODE,
"miden-standards-faucets-policies-transfer-allow-all.masp"
);
const TRANSFER_ALLOW_ALL_LIBRARY_PATH: &str =
"miden::standards::components::faucets::policies::transfer::allow_all";
procedure_root!(
ALLOW_ALL_TRANSFER_POLICY_ROOT,
TRANSFER_ALLOW_ALL_LIBRARY_PATH,
TransferAllowAll::PROC_NAME,
TransferAllowAll::code()
);
#[derive(Debug, Clone, Copy, Default)]
pub struct TransferAllowAll;
impl TransferAllowAll {
pub const NAME: &'static str = "miden::standards::faucets::policies::transfer::allow_all";
pub(crate) const PROC_NAME: &str = "check_policy";
pub fn code() -> &'static AccountComponentCode {
&ALLOW_ALL_TRANSFER_POLICY_CODE
}
pub fn root() -> AccountProcedureRoot {
*ALLOW_ALL_TRANSFER_POLICY_ROOT
}
}
impl From<TransferAllowAll> for AccountComponent {
fn from(_: TransferAllowAll) -> Self {
let metadata = AccountComponentMetadata::new(TransferAllowAll::NAME)
.with_description("`allow_all` transfer policy for callback-enabled faucets");
AccountComponent::new(TransferAllowAll::code().clone(), vec![], metadata).expect(
"`allow_all` transfer policy component should satisfy the requirements of a valid account component",
)
}
}