Refactor handle_obliteration
This commit is contained in:
parent
614849db78
commit
d2a3147120
@ -74,33 +74,28 @@ impl ProcessState {
|
||||
}
|
||||
|
||||
/// This is a simplified and streamlined validation for obliteration state
|
||||
fn handle_obliteration(&self, members_list: &OutPointMemberMap) -> anyhow::Result<()> {
|
||||
// We need an Apophis role
|
||||
if let Some(apophis) = self.roles.get(SpecialRoles::APOPHIS.to_string().as_str()) {
|
||||
// Apophis should have only one rule
|
||||
if apophis.validation_rules.len() != 1 { return Err(anyhow::Error::msg("Should have only one rule")); };
|
||||
let obliteration_rule = apophis.validation_rules.get(0).unwrap();
|
||||
fn handle_obliteration(&self, apophis: &RoleDefinition, members_list: &OutPointMemberMap) -> anyhow::Result<()> {
|
||||
// Apophis should have only one rule
|
||||
if apophis.validation_rules.len() != 1 { return Err(anyhow::Error::msg("Should have only one rule")); };
|
||||
let obliteration_rule = apophis.validation_rules.get(0).unwrap();
|
||||
|
||||
let empty_field = "";
|
||||
// This rule should have only one empty string as field
|
||||
if obliteration_rule.fields.len() != 1 { return Err(anyhow::Error::msg("Should have only one field")); };
|
||||
if obliteration_rule.fields.get(0).unwrap() != empty_field { return Err(anyhow::Error::msg("Field should be empty")); };
|
||||
let empty_field = "";
|
||||
// This rule should have only one empty string as field
|
||||
if obliteration_rule.fields.len() != 1 { return Err(anyhow::Error::msg("Should have only one field")); };
|
||||
if obliteration_rule.fields.get(0).unwrap() != empty_field { return Err(anyhow::Error::msg("Field should be empty")); };
|
||||
|
||||
let members: Vec<&Member> = apophis.members.iter()
|
||||
.filter_map(|outpoint| {
|
||||
members_list.0.get(outpoint)
|
||||
})
|
||||
.collect();
|
||||
let members: Vec<&Member> = apophis.members.iter()
|
||||
.filter_map(|outpoint| {
|
||||
members_list.0.get(outpoint)
|
||||
})
|
||||
.collect();
|
||||
|
||||
if apophis.validation_rules.iter().all(
|
||||
|r| r.is_satisfied(empty_field, [0u8; 32], &self.validation_tokens, &members).is_ok()
|
||||
) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow::Error::msg("Apophis is not satisfied"))
|
||||
}
|
||||
if apophis.validation_rules.iter().all(
|
||||
|r| r.is_satisfied(empty_field, [0u8; 32], &self.validation_tokens, &members).is_ok()
|
||||
) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow::Error::msg("Missing an apophis role"))
|
||||
Err(anyhow::Error::msg("Apophis is not satisfied"))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user