use alloc::string::{String, ToString};
use alloc::vec::Vec;
use miden_protocol::account::AccountProcedureRoot;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AccountComponentInterface {
BasicWallet,
NoteCreator,
FungibleFaucet,
CodeInspection,
Authority,
Ownable2Step,
RoleBasedAccessControl,
AuthSingleSig,
AuthMultisig,
AuthMultisigSmart,
AuthGuardedMultisig,
AuthNoAuth,
AuthNetworkAccount,
AuthTxFeeCollector,
CustomAuth(AccountProcedureRoot),
Custom(Vec<AccountProcedureRoot>),
}
impl AccountComponentInterface {
pub fn name(&self) -> String {
match self {
AccountComponentInterface::BasicWallet => "Basic Wallet".to_string(),
AccountComponentInterface::NoteCreator => "Note Creator".to_string(),
AccountComponentInterface::FungibleFaucet => "Fungible Faucet".to_string(),
AccountComponentInterface::CodeInspection => "Code Inspection".to_string(),
AccountComponentInterface::Authority => "Authority".to_string(),
AccountComponentInterface::Ownable2Step => "Ownable2Step".to_string(),
AccountComponentInterface::RoleBasedAccessControl => {
"Role Based Access Control".to_string()
},
AccountComponentInterface::AuthSingleSig => "SingleSig".to_string(),
AccountComponentInterface::AuthMultisig => "Multisig".to_string(),
AccountComponentInterface::AuthMultisigSmart => "Multisig Smart".to_string(),
AccountComponentInterface::AuthGuardedMultisig => "Guarded Multisig".to_string(),
AccountComponentInterface::AuthNoAuth => "No Auth".to_string(),
AccountComponentInterface::AuthNetworkAccount => "Network Account Auth".to_string(),
AccountComponentInterface::AuthTxFeeCollector => "Tx Fee Collector Auth".to_string(),
AccountComponentInterface::CustomAuth(proc_root) => {
format!("Custom Auth({})", shortened_mast_root(proc_root))
},
AccountComponentInterface::Custom(proc_root_vec) => {
let result =
proc_root_vec.iter().map(shortened_mast_root).collect::<Vec<_>>().join(", ");
format!("Custom([{result}])")
},
}
}
pub fn is_auth_component(&self) -> bool {
matches!(
self,
AccountComponentInterface::AuthSingleSig
| AccountComponentInterface::AuthMultisig
| AccountComponentInterface::AuthMultisigSmart
| AccountComponentInterface::AuthGuardedMultisig
| AccountComponentInterface::AuthNoAuth
| AccountComponentInterface::AuthNetworkAccount
| AccountComponentInterface::AuthTxFeeCollector
| AccountComponentInterface::CustomAuth(_)
)
}
}
fn shortened_mast_root(proc_root: &AccountProcedureRoot) -> String {
proc_root.mast_root().to_hex()[..9].to_string()
}