use anchor_lang::{prelude::*, AnchorDeserialize};
pub const SEED_FEE: &[u8] = b"fee";
#[account]
#[derive(Debug)]
pub struct Fee {
pub distributable_balance: u64,
pub worker: Pubkey,
}
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) -> Result<()>;
}
impl FeeAccount for Account<'_, Fee> {
fn pubkey(&self) -> Pubkey {
Fee::pubkey(self.worker)
}
fn init(&mut self, worker: Pubkey) -> Result<()> {
self.distributable_balance = 0;
self.worker = worker;
Ok(())
}
}