1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::rules::validation::Validation;
use crate::utils::Error;
use macros::Rule;
use odra::types::Balance;

/// Verifies if the proposed payment does not exceeds the budget.
/// May return [Error::PaymentExceedsMaxBudget].
#[derive(Rule)]
pub struct DoesProposedPaymentExceedBudget {
    proposed_payment: Balance,
    max_budget: Balance,
}

impl Validation for DoesProposedPaymentExceedBudget {
    fn validate(&self) -> Result<(), Error> {
        if self.proposed_payment > self.max_budget {
            return Err(Error::PaymentExceedsMaxBudget);
        }

        Ok(())
    }
}