Add process obliteration code
This commit is contained in:
parent
2cbbfa3eae
commit
5db6f31b57
@ -9,12 +9,11 @@ use sp_client::bitcoin::{OutPoint, Transaction};
|
|||||||
use tsify::Tsify;
|
use tsify::Tsify;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
pcd::{Member, Pcd, PcdCommitments, RoleDefinition, Roles},
|
pcd::{Member, Pcd, PcdCommitments, RoleDefinition, Roles}, serialization::{deserialize_hex, hex_array_btree, serialize_hex}, signature::{AnkHash, AnkValidationNoHash, AnkValidationYesHash, Proof}, MutexExt, SpecialRoles
|
||||||
signature::{AnkHash, AnkValidationNoHash, AnkValidationYesHash, Proof},
|
|
||||||
MutexExt,
|
|
||||||
serialization::{hex_array_btree, serialize_hex, deserialize_hex},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const OBLITERATION_MSG: [u8; 32] = [167, 164, 238, 168, 233, 235, 152, 107, 194, 162, 145, 42, 140, 11, 244, 71, 252, 67, 204, 207, 114, 85, 209, 80, 129, 190, 151, 172, 77, 174, 243, 1];
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, Tsify)]
|
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, Tsify)]
|
||||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||||
pub struct ProcessState {
|
pub struct ProcessState {
|
||||||
@ -99,6 +98,16 @@ impl ProcessState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is a simplified and streamlined validation for obliteration state
|
||||||
|
fn handle_obliteration(&self) -> anyhow::Result<()> {
|
||||||
|
// We need an Apophis role
|
||||||
|
if let Some(apophis) = self.roles.get(SpecialRoles::APOPHIS.to_string().as_str()) {
|
||||||
|
apophis.is_satisfied(vec!["".to_owned()], [0u8; 32], &self.validation_tokens)
|
||||||
|
} else {
|
||||||
|
Err(anyhow::Error::msg("Missing an apophis role"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_valid(&self, previous_state: Option<&ProcessState>) -> anyhow::Result<()> {
|
pub fn is_valid(&self, previous_state: Option<&ProcessState>) -> anyhow::Result<()> {
|
||||||
if self.validation_tokens.is_empty() {
|
if self.validation_tokens.is_empty() {
|
||||||
return Err(anyhow::anyhow!(
|
return Err(anyhow::anyhow!(
|
||||||
@ -106,6 +115,11 @@ impl ProcessState {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.validation_tokens.get(0).unwrap().get_message() == OBLITERATION_MSG {
|
||||||
|
// We're dealing with a destruction update
|
||||||
|
return self.handle_obliteration();
|
||||||
|
}
|
||||||
|
|
||||||
// Compute modified fields
|
// Compute modified fields
|
||||||
let modified_fields = self.list_modified_fields(previous_state);
|
let modified_fields = self.list_modified_fields(previous_state);
|
||||||
|
|
||||||
@ -122,6 +136,7 @@ impl ProcessState {
|
|||||||
// We allow for a special case with a role that works only for initial state
|
// We allow for a special case with a role that works only for initial state
|
||||||
// That's optional though
|
// That's optional though
|
||||||
if previous_state.is_some() && *role_name == crate::SpecialRoles::DEMIURGE.to_string() { return None; }
|
if previous_state.is_some() && *role_name == crate::SpecialRoles::DEMIURGE.to_string() { return None; }
|
||||||
|
if *role_name == crate::SpecialRoles::APOPHIS.to_string() { return None; } // We handle destructions separately
|
||||||
let mut filtered_role_def = role_def.clone();
|
let mut filtered_role_def = role_def.clone();
|
||||||
let rules = filtered_role_def.get_applicable_rules(field);
|
let rules = filtered_role_def.get_applicable_rules(field);
|
||||||
filtered_role_def.validation_rules =
|
filtered_role_def.validation_rules =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user