clockwork_network/instructions/
snapshot_kickoff.rs

1use {
2    crate::state::*,
3    anchor_lang::{prelude::*, solana_program::instruction::Instruction, system_program},
4    clockwork_crank::state::{CrankResponse, Queue, SEED_QUEUE},
5};
6
7#[derive(Accounts)]
8pub struct SnapshotKickoff<'info> {
9    #[account(seeds = [SEED_AUTHORITY], bump)]
10    pub authority: Box<Account<'info, Authority>>,
11
12    #[account(mut, seeds = [SEED_REGISTRY], bump)]
13    pub registry: Account<'info, Registry>,
14
15    #[account(
16        signer, 
17        seeds = [
18            SEED_QUEUE, 
19            authority.key().as_ref(), 
20            "snapshot".as_bytes()
21        ], 
22        seeds::program = clockwork_crank::ID,
23        bump,
24        has_one = authority
25    )]
26    pub snapshot_queue: Account<'info, Queue>,
27}
28
29pub fn handler(ctx: Context<SnapshotKickoff>) -> Result<CrankResponse> {
30    // Get accounts
31    let authority = &ctx.accounts.authority;
32    let registry = &mut ctx.accounts.registry;
33    let snapshot_queue = &ctx.accounts.snapshot_queue;
34
35    // Build the next crank instruction
36    Ok(CrankResponse { next_instruction:
37        Some(Instruction {
38            program_id: crate::ID,
39            accounts: vec![
40                AccountMeta::new_readonly(authority.key(), false),
41                AccountMeta::new_readonly(Config::pubkey(), false),
42                AccountMeta::new(clockwork_crank::payer::ID, true),
43                AccountMeta::new(registry.key(), false),
44                AccountMeta::new(Snapshot::pubkey(registry.snapshot_count), false),
45                AccountMeta::new_readonly(snapshot_queue.key(), true),
46                AccountMeta::new_readonly(system_program::ID, false),
47            ],
48            data: clockwork_crank::anchor::sighash("snapshot_create").into(),
49        }.into()) 
50    })
51}