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 id of the variable.
12    pub id: u64,
13
14    /// The provider of the entropy data.
15    pub provider: Pubkey,
16
17    /// The commit provided by Entropy provider.
18    pub commit: [u8; 32],
19
20    /// The revealed seed.
21    pub seed: [u8; 32],
22
23    /// The slot hash
24    pub slot_hash: [u8; 32],
25
26    /// The current value of the variable.
27    pub value: [u8; 32],
28
29    /// The number of random variables remaining to be sampled.
30    pub samples: u64,
31
32    /// Whether or not the Entropy provider should automatically sample the slot hash.
33    pub is_auto: u64,
34
35    /// The slot at which the variable was opened.
36    pub start_at: u64,
37
38    /// The slot at which the variable should sample the slothash.
39    pub end_at: u64,
40}
41
42impl Var {
43    pub fn is_valid(&self, seed: [u8; 32]) -> bool {
44        if self.slot_hash == [0; 32] {
45            return false;
46        }
47        if self.value != [0; 32] {
48            return false;
49        }
50        if self.samples == 0 {
51            return false;
52        }
53        let expected_commit = solana_program::keccak::hash(&seed).to_bytes();
54        expected_commit == self.commit
55    }
56}
57
58account!(EntropyAccount, Var);