use crate::errors::RegistryError;
use super::register_epoch::{EpochPda, ForesterEpochPda};
use anchor_lang::prelude::*;
pub fn report_work_instruction(
forester_epoch_pda: &mut ForesterEpochPda,
epoch_pda: &mut EpochPda,
current_slot: u64,
) -> Result<()> {
epoch_pda
.protocol_config
.is_report_work_phase(current_slot, epoch_pda.epoch)?;
if forester_epoch_pda.epoch != epoch_pda.epoch {
return err!(RegistryError::InvalidEpochAccount);
}
if forester_epoch_pda.has_reported_work {
return err!(RegistryError::ForesterAlreadyRegistered);
}
forester_epoch_pda.has_reported_work = true;
epoch_pda.total_work += forester_epoch_pda.work_counter;
Ok(())
}
#[derive(Accounts)]
pub struct ReportWork<'info> {
authority: Signer<'info>,
#[account(mut, has_one = authority)]
pub forester_epoch_pda: Account<'info, ForesterEpochPda>,
#[account(mut)]
pub epoch_pda: Account<'info, EpochPda>,
}