use crate::param::{AccountGroupId, AccountId};
use crate::storage::{self, StorageBuilder};
use super::{AccountControl, AccountGroups, AccountGroupsHandle, GroupLookup};
pub struct AccountAdjustmentContext<StorageFactory>
where
StorageFactory: storage::LockingPolicyFactory + storage::CreateStorageFor<AccountId> + 'static,
{
pub account_control: AccountControl<StorageFactory>,
group_lookup: GroupLookup<StorageFactory>,
}
impl<StorageFactory> AccountAdjustmentContext<StorageFactory>
where
StorageFactory: storage::LockingPolicyFactory + storage::CreateStorageFor<AccountId> + 'static,
{
pub(crate) fn with_groups(
account_control: AccountControl<StorageFactory>,
account_groups: AccountGroupsHandle<StorageFactory>,
account: AccountId,
) -> Self {
Self {
account_control,
group_lookup: GroupLookup::new(account_groups, Some(account)),
}
}
pub fn new(account_control: AccountControl<StorageFactory>, account: AccountId) -> Self
where
StorageFactory: Default,
{
let builder = StorageBuilder::new(StorageFactory::default());
let handle = AccountGroupsHandle::from_inner(StorageFactory::new_shared(
AccountGroups::new(&builder),
));
Self::with_groups(account_control, handle, account)
}
pub fn account_group(&self) -> Option<AccountGroupId> {
self.group_lookup.group()
}
#[cfg(test)]
pub(crate) fn new_test(account_control: AccountControl<StorageFactory>) -> Self
where
StorageFactory: Default,
{
Self::new(account_control, AccountId::from_u64(0))
}
}