clockwork_http/instructions/
initialize.rs

1use {
2    crate::state::{Config, ConfigAccount, SEED_CONFIG},
3    anchor_lang::{prelude::*, solana_program::system_program},
4    std::mem::size_of,
5};
6
7#[derive(Accounts)]
8pub struct Initialize<'info> {
9    #[account(mut)]
10    pub admin: Signer<'info>,
11
12    #[account(
13        init,
14        seeds = [SEED_CONFIG],
15        bump,
16        payer = admin,
17        space = 8 + size_of::<Config>(),
18    )]
19    pub config: Account<'info, Config>,
20
21    #[account(address = system_program::ID)]
22    pub system_program: Program<'info, System>,
23}
24
25pub fn handler<'info>(ctx: Context<Initialize>) -> Result<()> {
26    // Get accounts
27    let admin = &ctx.accounts.admin;
28    let config = &mut ctx.accounts.config;
29
30    // Initialize the config account
31    config.new(admin.key())?;
32
33    Ok(())
34}