sol_cerberus/instructions/
update_cache.rs

1use crate::state::app::*;
2use crate::utils::utc_now;
3use anchor_lang::prelude::*;
4
5#[derive(Accounts)]
6pub struct UpdateCache<'info> {
7    pub authority: Signer<'info>, // Only current Authority is allowed
8    #[account(
9        mut,
10        has_one = authority,
11        seeds = [b"app".as_ref(), app.id.key().as_ref()], 
12        bump = app.bump,
13    )]
14    pub app: Account<'info, App>,
15    pub system_program: Program<'info, System>,
16}
17
18pub fn update_cache(ctx: Context<UpdateCache>, cache_updated: u8) -> Result<()> {
19    let app = &mut ctx.accounts.app;
20    let now = utc_now();
21    if cache_updated == CacheUpdated::Roles as u8 {
22        app.roles_updated_at = now;
23    } else {
24        app.rules_updated_at = now;
25    }
26    emit!(AppChanged {
27        time: now,
28        app_id: ctx.accounts.app.id,
29        authority: ctx.accounts.app.authority,
30    });
31    Ok(())
32}