1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use {
crate::{errors::*, state::*},
anchor_lang::{prelude::*, solana_program::system_program},
std::mem::size_of,
};
#[derive(Accounts)]
#[instruction(
timestamp: u64,
frame_bump: u8,
list_bump: u8,
)]
pub struct WindowCreate<'info> {
#[account(
mut,
seeds = [SEED_AUTHORITY],
bump = authority.bump,
owner = crate::ID,
)]
pub authority: Account<'info, Authority>,
#[account(
constraint = timestamp % config.frame_interval == 0 @ ErrorCode::InvalidTimestamp,
)]
pub clock: Sysvar<'info, Clock>,
#[account(
seeds = [SEED_CONFIG],
bump = config.bump,
owner = crate::ID
)]
pub config: Account<'info, Config>,
#[account(
init,
seeds = [
SEED_FRAME,
timestamp.to_be_bytes().as_ref()
],
bump = frame_bump,
payer = payer,
space = 8 + size_of::<Frame>(),
)]
pub frame: Account<'info, Frame>,
#[account(address = cronos_indexer::ID)]
pub indexer_program: Program<'info, cronos_indexer::program::Indexer>,
#[account(mut)]
pub list: AccountInfo<'info>,
#[account(mut)]
pub payer: Signer<'info>,
#[account(address = system_program::ID)]
pub system_program: Program<'info, System>,
}
pub fn handler(
ctx: Context<WindowCreate>,
timestamp: u64,
frame_bump: u8,
list_bump: u8,
) -> ProgramResult {
let authority = &ctx.accounts.authority;
let frame = &mut ctx.accounts.frame;
let indexer_program = &ctx.accounts.indexer_program;
let list = &ctx.accounts.list;
let payer = &ctx.accounts.payer;
let system_program = &ctx.accounts.system_program;
frame.timestamp = timestamp;
frame.bump = frame_bump;
cronos_indexer::cpi::create_list(
CpiContext::new_with_signer(
indexer_program.to_account_info(),
cronos_indexer::cpi::accounts::CreateList {
list: list.to_account_info(),
owner: authority.to_account_info(),
payer: payer.to_account_info(),
namespace: frame.to_account_info(),
system_program: system_program.to_account_info(),
},
&[&[SEED_AUTHORITY, &[authority.bump]]],
),
list_bump,
)
}