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