gmsol_store/instructions/
feature.rs

1use anchor_lang::prelude::*;
2
3use crate::{
4    states::{
5        feature::{ActionDisabledFlag, DomainDisabledFlag},
6        Store,
7    },
8    utils::internal,
9};
10
11/// The accounts definition for [`toggle_feature`](crate::gmsol_store::toggle_feature).
12#[derive(Accounts)]
13pub struct ToggleFeature<'info> {
14    /// Authority.
15    pub authority: Signer<'info>,
16    /// Store.
17    #[account(mut)]
18    pub store: AccountLoader<'info, Store>,
19}
20
21/// Enable or disable the given feature.
22/// CHECK: only `FEATURE_KEEPER` can use this instruction.
23pub(crate) fn unchecked_toggle_feature(
24    ctx: Context<ToggleFeature>,
25    domain: DomainDisabledFlag,
26    action: ActionDisabledFlag,
27    enable: bool,
28) -> Result<()> {
29    ctx.accounts
30        .store
31        .load_mut()?
32        .set_feature_disabled(domain, action, !enable);
33    Ok(())
34}
35
36impl<'info> internal::Authentication<'info> for ToggleFeature<'info> {
37    fn authority(&self) -> &Signer<'info> {
38        &self.authority
39    }
40
41    fn store(&self) -> &AccountLoader<'info, Store> {
42        &self.store
43    }
44}