From 2ce8c4622ed9c23be675a6143390c393d2a1e799 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Fri, 21 Jun 2024 00:22:19 +0300 Subject: [PATCH] transaction commit body type --- ng-repo/src/types.rs | 20 +++++++++-- ng-verifier/src/commits/transaction.rs | 47 ++++++++++++++++++++++++++ ng-verifier/src/request_processor.rs | 1 - 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/ng-repo/src/types.rs b/ng-repo/src/types.rs index 1802841..d18bd44 100644 --- a/ng-repo/src/types.rs +++ b/ng-repo/src/types.rs @@ -1885,6 +1885,14 @@ pub enum Transaction { V0(TransactionV0), } +impl Transaction { + pub fn body_type(&self) -> u8 { + match self { + Self::V0(v0) => v0[0], + } + } +} + /// Add a new binary file in a branch /// /// FILES: the file ObjectRef @@ -2401,8 +2409,12 @@ impl CommitBodyV0 { Self::BranchCapRefresh(_) => CommitType::BranchCapRefresh, Self::UpdateBranch(_) => CommitType::UpdateBranch, Self::Snapshot(_) => CommitType::Snapshot, - Self::AsyncTransaction(_) => CommitType::Transaction, - Self::SyncTransaction(_) => CommitType::Transaction, + Self::AsyncTransaction(t) | Self::SyncTransaction(t) => match t.body_type() { + 0 => CommitType::TransactionGraph, + 1 => CommitType::TransactionDiscrete, + 2 => CommitType::TransactionBoth, + _ => panic!("invalid TransactionBody"), + }, Self::AddFile(_) => CommitType::FileAdd, Self::RemoveFile(_) => CommitType::FileRemove, Self::Compact(_) => CommitType::Compact, @@ -2424,7 +2436,9 @@ impl CommitBodyV0 { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub enum CommitType { - Transaction, + TransactionGraph, + TransactionDiscrete, + TransactionBoth, FileAdd, FileRemove, Snapshot, diff --git a/ng-verifier/src/commits/transaction.rs b/ng-verifier/src/commits/transaction.rs index 0a90e0c..99c2f95 100644 --- a/ng-verifier/src/commits/transaction.rs +++ b/ng-verifier/src/commits/transaction.rs @@ -45,8 +45,16 @@ pub enum DiscreteTransaction { Automerge(Vec), } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum TransactionBodyType { + Graph, + Discrete, + Both, +} + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TransactionBody { + body_type: TransactionBodyType, graph: Option, discrete: Option, } @@ -340,6 +348,7 @@ impl Verifier { }; let mut transac = TransactionBody { + body_type: TransactionBodyType::Graph, graph: Some(graph_transac), discrete: None, }; @@ -556,3 +565,41 @@ impl Verifier { } } } + +#[cfg(test)] +mod test { + + use super::{TransactionBody, TransactionBodyType}; + use ng_repo::log::*; + use serde_bare::to_vec; + + #[test] + pub fn test_transaction_body() { + let body = TransactionBody { + body_type: TransactionBodyType::Graph, + graph: None, + discrete: None, + }; + let ser = to_vec(&body).unwrap(); + + log_debug!("graph {:?}", ser); + + let body = TransactionBody { + body_type: TransactionBodyType::Discrete, + graph: None, + discrete: None, + }; + let ser = to_vec(&body).unwrap(); + + log_debug!("discrete {:?}", ser); + + let body = TransactionBody { + body_type: TransactionBodyType::Both, + graph: None, + discrete: None, + }; + let ser = to_vec(&body).unwrap(); + + log_debug!("both {:?}", ser); + } +} diff --git a/ng-verifier/src/request_processor.rs b/ng-verifier/src/request_processor.rs index 1eae56e..87035af 100644 --- a/ng-verifier/src/request_processor.rs +++ b/ng-verifier/src/request_processor.rs @@ -9,7 +9,6 @@ //! Processor for each type of AppRequest -use std::collections::HashMap; use std::sync::Arc; use futures::channel::mpsc;