clockwork_http/instructions/
api_new.rs1use {
2 crate::state::{Api, ApiAccount, SEED_API},
3 anchor_lang::{prelude::*, system_program},
4 std::mem::size_of,
5};
6
7#[derive(Accounts)]
8#[instruction(base_url: String)]
9pub struct ApiNew<'info> {
10 #[account()]
11 pub ack_authority: SystemAccount<'info>,
12
13 #[account(
14 init,
15 seeds = [
16 SEED_API,
17 authority.key().as_ref(),
18 base_url.as_bytes().as_ref(),
19 ],
20 bump,
21 payer = payer,
22 space = 8 + size_of::<Api>() + base_url.len(),
23 )]
24 pub api: Account<'info, Api>,
25
26 #[account()]
27 pub authority: Signer<'info>,
28
29 #[account(mut)]
30 pub payer: Signer<'info>,
31
32 #[account(address = system_program::ID)]
33 pub system_program: Program<'info, System>,
34}
35
36pub fn handler<'info>(ctx: Context<ApiNew>, base_url: String) -> Result<()> {
37 let ack_authority = &ctx.accounts.ack_authority;
39 let authority = &mut ctx.accounts.authority;
40 let api = &mut ctx.accounts.api;
41
42 api.new(ack_authority.key(), authority.key(), base_url)?;
46
47 Ok(())
48}