diff --git a/src/network.rs b/src/network.rs index 580dbd4..bed3410 100644 --- a/src/network.rs +++ b/src/network.rs @@ -80,26 +80,35 @@ pub struct CommitMessage { impl CommitMessage { /// Create a new commitment message for a creation/update transaction - /// validation_tokens must be empty - pub fn new_update_commitment( + pub fn new( process_id: OutPoint, pcd_commitment: PcdCommitments, roles: Roles, public_data: Pcd, + validation_tokens: Vec ) -> Self { Self { process_id, pcd_commitment, roles, public_data, - validation_tokens: vec![], + validation_tokens, error: None, } } - /// Set the validation tokens for a pending commitment - pub fn set_validation_tokens(&mut self, validation_tokens: Vec) { - self.validation_tokens = validation_tokens; + /// Add validation tokens for a pending commitment + pub fn add_validation_tokens(&mut self, validation_tokens: Vec) { + self.validation_tokens.extend_from_slice(&validation_tokens); + self.validation_tokens.sort_unstable(); + self.validation_tokens.dedup(); + } + + /// Remove all validation tokens + /// This should rarely be useful, and we'd rather let caller copy all he needs, sorts on its own + /// and clear here + pub fn clear_validation_tokens(&mut self) { + self.validation_tokens = vec![]; } }