sablier_network_program/state/
penalty.rs

1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3use crate::constants::SEED_PENALTY;
4
5/// Escrows the lamport balance owed to a particular worker.
6#[account]
7#[derive(Debug, InitSpace)]
8pub struct Penalty {
9    /// The worker who was penalized.
10    pub worker: Pubkey,
11    pub bump: u8,
12}
13
14impl Penalty {
15    /// Derive the pubkey of a fee account.
16    pub fn pubkey(worker: Pubkey) -> Pubkey {
17        Pubkey::find_program_address(&[SEED_PENALTY, worker.as_ref()], &crate::ID).0
18    }
19}
20
21/// Trait for reading and writing to a penalty account.
22pub trait PenaltyAccount {
23    /// Get the pubkey of the penalty account.
24    fn pubkey(&self) -> Pubkey;
25
26    /// Initialize the account to hold penalty object.
27    fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()>;
28}
29
30impl PenaltyAccount for Account<'_, Penalty> {
31    fn pubkey(&self) -> Pubkey {
32        Penalty::pubkey(self.worker)
33    }
34
35    fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()> {
36        self.worker = worker;
37        self.bump = bump;
38        Ok(())
39    }
40}