Update to latest CommitMessage

This commit is contained in:
NicolasCantu 2025-02-04 16:23:00 +01:00
parent 1fe174190f
commit f0db7a1f23

View File

@ -4,9 +4,8 @@ use anyhow::Result;
use rand::{thread_rng, RngCore}; use rand::{thread_rng, RngCore};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use sp_client::bitcoin::consensus::serialize;
use sp_client::bitcoin::hex::DisplayHex; use sp_client::bitcoin::hex::DisplayHex;
use sp_client::bitcoin::{OutPoint, Transaction}; use sp_client::bitcoin::OutPoint;
use tsify::Tsify; use tsify::Tsify;
use crate::error::AnkError; use crate::error::AnkError;
@ -74,7 +73,7 @@ impl AnkFlag {
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Tsify)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)] #[tsify(into_wasm_abi, from_wasm_abi)]
pub struct CommitMessage { pub struct CommitMessage {
pub init_tx: String, // Can be tx or txid of the first transaction of the chain, which is maybe not ideal pub process_id: OutPoint,
pub pcd_commitment: Value, // map of field <=> hash of the clear value pub pcd_commitment: Value, // map of field <=> hash of the clear value
pub roles: HashMap<String, RoleDefinition>, // Can be hashed and compared with the value above pub roles: HashMap<String, RoleDefinition>, // Can be hashed and compared with the value above
pub validation_tokens: Vec<Proof>, pub validation_tokens: Vec<Proof>,
@ -82,33 +81,15 @@ pub struct CommitMessage {
} }
impl CommitMessage { impl CommitMessage {
/// Create a new commitment message for the first transaction of the chain /// Create a new commitment message for a creation/update transaction
/// init_tx must be the hex string of the transaction
/// validation_tokens must be empty
pub fn new_first_commitment(
transaction: Transaction,
pcd_commitment: Value,
roles: HashMap<String, RoleDefinition>,
) -> Self {
Self {
init_tx: serialize(&transaction).to_lower_hex_string(),
pcd_commitment,
roles,
validation_tokens: vec![],
error: None,
}
}
/// Create a new commitment message for an update transaction
/// init_tx must be the hex string of the txid of the first commitment transaction
/// validation_tokens must be empty /// validation_tokens must be empty
pub fn new_update_commitment( pub fn new_update_commitment(
init_tx: OutPoint, process_id: OutPoint,
pcd_commitment: Value, pcd_commitment: Value,
roles: HashMap<String, RoleDefinition>, roles: HashMap<String, RoleDefinition>,
) -> Self { ) -> Self {
Self { Self {
init_tx: init_tx.to_string(), process_id,
pcd_commitment, pcd_commitment,
roles, roles,
validation_tokens: vec![], validation_tokens: vec![],