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