1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::bid_escrow::job::JobStatus;
use crate::rules::validation::Validation;
use crate::utils::Error;
use macros::Rule;
use odra::types::BlockTime;

/// Makes sure the [`Job`](crate::bid_escrow::job::Job) is in grace period state.
/// May return [Error::CannotSubmitJobProof] or [Error::GracePeriodNotStarted].
///
/// Read more about [`grace period`](crate::bid_escrow).
#[derive(Rule)]
pub struct IsGracePeriod {
    job_status: JobStatus,
    job_finish_time: BlockTime,
    block_time: BlockTime,
}

impl Validation for IsGracePeriod {
    fn validate(&self) -> Result<(), Error> {
        if self.job_status != JobStatus::Created {
            return Err(Error::CannotSubmitJobProof);
        }

        if self.job_finish_time >= self.block_time {
            return Err(Error::GracePeriodNotStarted);
        }
        Ok(())
    }
}