File size: 1,183 Bytes
224e773 | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | //! Constraint language definition
#[derive(Debug, Clone)]
pub enum Constraint {
Balance(String),
InvariantPreserved(String),
Entropy(f64),
ProofCertificate(String),
RuntimeSource(String),
IdentitySignature(String),
PhaseComplete(String),
}
#[derive(Debug, Clone)]
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()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn program_creation() {
let mut prog = ValidityProgram::new();
prog.add_constraint(Constraint::Balance("test".to_string()));
assert_eq!(prog.constraints.len(), 1);
}
}
|