entropy_api/state/
var.rs

1use steel::*;
2
3use super::EntropyAccount;
4
5#[repr(C)]
6#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
7pub struct Var {
8    /// The creator of the variable.
9    pub authority: Pubkey,
10
11    /// The commit provided by Entropy provider.
12    pub commit: [u8; 32],
13
14    /// The revealed seed.
15    pub seed: [u8; 32],
16
17    /// The slot hash
18    pub slot_hash: [u8; 32],
19
20    /// The current value of the variable.
21    pub value: [u8; 32],
22
23    /// The number of random variables remaining to be sampled.
24    pub samples: u64,
25
26    /// Whether or not the Entropy provider should automatically sample the slot hash.
27    pub is_auto: u64,
28
29    /// The slot at which the variable was opened.
30    pub start_at: u64,
31
32    /// The slot at which the variable should sample the slothash.
33    pub end_at: u64,
34}
35
36impl Var {
37    pub fn is_valid(&self, seed: [u8; 32]) -> bool {
38        if self.slot_hash == [0; 32] {
39            return false;
40        }
41        if self.value != [0; 32] {
42            return false;
43        }
44        if self.samples == 0 {
45            return false;
46        }
47        let expected_commit = solana_program::keccak::hash(&seed).to_bytes();
48        expected_commit == self.commit
49    }
50}
51
52account!(EntropyAccount, Var);