quarry_operator/
state.rs

1//! State structs.
2
3pub use crate::*;
4
5/// Operator state
6#[account]
7#[derive(Copy, Default, Debug, PartialEq, Eq)]
8pub struct Operator {
9    /// The base.
10    pub base: Pubkey,
11    /// Bump seed.
12    pub bump: u8,
13
14    /// The [Rewarder].
15    pub rewarder: Pubkey,
16    /// Can modify the authorities below.
17    pub admin: Pubkey,
18
19    /// Can call [quarry_mine::quarry_mine::set_annual_rewards].
20    pub rate_setter: Pubkey,
21    /// Can call [quarry_mine::quarry_mine::create_quarry].
22    pub quarry_creator: Pubkey,
23    /// Can call [quarry_mine::quarry_mine::set_rewards_share].
24    pub share_allocator: Pubkey,
25
26    /// When the [Operator] was last modified.
27    pub last_modified_ts: i64,
28    /// Auto-incrementing sequence number of the set of authorities.
29    /// Useful for checking if things were updated.
30    pub generation: u64,
31}
32
33impl Operator {
34    /// Number of bytes in an [Operator].
35    pub const LEN: usize = 32 + 1 + 32 + 32 + 32 + 32 + 32 + 8 + 8;
36
37    pub(crate) fn record_update(&mut self) -> Result<()> {
38        self.last_modified_ts = Clock::get()?.unix_timestamp;
39        self.generation = unwrap_int!(self.generation.checked_add(1));
40        Ok(())
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_operator_len() {
50        assert_eq!(
51            Operator::default().try_to_vec().unwrap().len(),
52            Operator::LEN
53        );
54    }
55}