transaction commit body type

pull/19/head
Niko PLP 6 months ago
parent 79eea0384e
commit 2ce8c4622e
  1. 20
      ng-repo/src/types.rs
  2. 47
      ng-verifier/src/commits/transaction.rs
  3. 1
      ng-verifier/src/request_processor.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,

@ -45,8 +45,16 @@ pub enum DiscreteTransaction {
Automerge(Vec<u8>),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum TransactionBodyType {
Graph,
Discrete,
Both,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransactionBody {
body_type: TransactionBodyType,
graph: Option<GraphTransaction>,
discrete: Option<DiscreteTransaction>,
}
@ -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);
}
}

@ -9,7 +9,6 @@
//! Processor for each type of AppRequest
use std::collections::HashMap;
use std::sync::Arc;
use futures::channel::mpsc;

Loading…
Cancel
Save