use alloc::vec::Vec;
use miden_protocol::account::AccountId;
#[cfg(test)]
mod test;
mod component;
pub use component::AccountComponentInterface;
mod extension;
pub use extension::{AccountComponentInterfaceExt, AccountInterfaceExt};
pub struct AccountInterface {
account_id: AccountId,
components: Vec<AccountComponentInterface>,
}
impl AccountInterface {
pub fn new(account_id: AccountId, components: Vec<AccountComponentInterface>) -> Self {
let auth_count = components.iter().filter(|c| c.is_auth_component()).count();
assert_eq!(
auth_count, 1,
"account interface must contain exactly one auth component, found {auth_count}"
);
Self { account_id, components }
}
pub fn id(&self) -> &AccountId {
&self.account_id
}
pub fn is_private(&self) -> bool {
self.account_id.is_private()
}
pub fn is_public(&self) -> bool {
self.account_id.is_public()
}
pub fn components(&self) -> &Vec<AccountComponentInterface> {
&self.components
}
pub fn auth_component(&self) -> &AccountComponentInterface {
self.components
.iter()
.find(|c| c.is_auth_component())
.expect("AccountInterface invariant: exactly one auth component present")
}
}