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
use crate::*;

/// Keypair account used as a fallback for listening to randomness requests.
/// These accounts are ephemeral and are intended to be closed upon completion.
#[account]
#[derive(Debug, Default, InitSpace)]
pub struct SimpleRandomnessV1Account {
    /// Flag for determining whether the request has been completed.
    pub is_completed: u8,
    pub num_bytes: u8,
    pub user: Pubkey,
    pub escrow: Pubkey,
    pub request_slot: u64,
    pub callback: Callback,
    pub compute_units: u32,
    pub priority_fee_micro_lamports: u64,
    #[max_len(256)]
    pub error_message: String,
}
impl SimpleRandomnessV1Account {
    pub fn space(callback: &Callback) -> usize {
        let base: usize = 8  // discriminator
            + std::mem::size_of::<SimpleRandomnessV1Account>();

        base
        + (callback.ix_data.len()) // callback ix data len
        + (std::mem::size_of::<AccountMetaBorsh>() * callback.accounts.len())
        + 256 // error message
    }
}