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
use crate::rules::validation::Validation;
use crate::utils::Error;
use macros::Rule;
use odra::types::Balance;

/// Verifies if the actual payment matches the proposed payment. May return [Error::PurseBalanceMismatch].
#[derive(Rule)]
pub struct DoesProposedPaymentMatchTransferred {
    proposed_payment: Balance,
    transferred: Balance,
    declared: Balance,
}

impl Validation for DoesProposedPaymentMatchTransferred {
    fn validate(&self) -> Result<(), Error> {
        if (self.proposed_payment != self.transferred)
            || (self.proposed_payment != self.declared)
            || self.transferred != self.declared
        {
            return Err(Error::PurseBalanceMismatch);
        }

        Ok(())
    }
}