miclockwork_network_program/state/
penalty.rs1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_PENALTY: &[u8] = b"penalty";
4
5#[account]
7#[derive(Debug)]
8pub struct Penalty {
9 pub worker: Pubkey,
11}
12
13impl Penalty {
14 pub fn pubkey(worker: Pubkey) -> Pubkey {
16 Pubkey::find_program_address(&[SEED_PENALTY, worker.as_ref()], &crate::ID).0
17 }
18}
19
20pub trait PenaltyAccount {
22 fn pubkey(&self) -> Pubkey;
24
25 fn init(&mut self, worker: Pubkey) -> Result<()>;
27}
28
29impl PenaltyAccount for Account<'_, Penalty> {
30 fn pubkey(&self) -> Pubkey {
31 Penalty::pubkey(self.worker)
32 }
33
34 fn init(&mut self, worker: Pubkey) -> Result<()> {
35 self.worker = worker;
36 Ok(())
37 }
38}