use anchor_lang::{prelude::*, AnchorDeserialize};
use crate::constants::SEED_PENALTY;
#[account]
#[derive(Debug, InitSpace)]
pub struct Penalty {
pub worker: Pubkey,
pub bump: u8,
}
impl Penalty {
pub fn pubkey(worker: Pubkey) -> Pubkey {
Pubkey::find_program_address(&[SEED_PENALTY, worker.as_ref()], &crate::ID).0
}
}
pub trait PenaltyAccount {
fn pubkey(&self) -> Pubkey;
fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()>;
}
impl PenaltyAccount for Account<'_, Penalty> {
fn pubkey(&self) -> Pubkey {
Penalty::pubkey(self.worker)
}
fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()> {
self.worker = worker;
self.bump = bump;
Ok(())
}
}