| //! Constraint language definition | |
| pub enum Constraint { | |
| Balance(String), | |
| InvariantPreserved(String), | |
| Entropy(f64), | |
| ProofCertificate(String), | |
| RuntimeSource(String), | |
| IdentitySignature(String), | |
| PhaseComplete(String), | |
| } | |
| pub struct ValidityProgram { | |
| pub constraints: Vec<Constraint>, | |
| pub otherwise_reject: bool, | |
| } | |
| impl ValidityProgram { | |
| pub fn new() -> Self { | |
| ValidityProgram { | |
| constraints: Vec::new(), | |
| otherwise_reject: false, | |
| } | |
| } | |
| pub fn add_constraint(&mut self, constraint: Constraint) { | |
| self.constraints.push(constraint); | |
| } | |
| pub fn set_reject_on_fail(&mut self, reject: bool) { | |
| self.otherwise_reject = reject; | |
| } | |
| } | |
| impl Default for ValidityProgram { | |
| fn default() -> Self { | |
| Self::new() | |
| } | |
| } | |
| mod tests { | |
| use super::*; | |
| fn program_creation() { | |
| let mut prog = ValidityProgram::new(); | |
| prog.add_constraint(Constraint::Balance("test".to_string())); | |
| assert_eq!(prog.constraints.len(), 1); | |
| } | |
| } | |