Skip to content

Commit

Permalink
Add subtree API to context
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiencs authored and tizoc committed Jun 13, 2021
1 parent f9fda02 commit e9898b3
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tezos/new_context/src/ffi.rs
Expand Up @@ -121,7 +121,7 @@ ocaml_export! {
let date = date.to_rust(rt);
let author = author.to_rust(rt);

let result = context.hash(author, message, date)
let result = ShellContextApi::hash(context, author, message, date)
.map_err(|err| format!("{:?}", err));

result.to_ocaml(rt)
Expand Down
10 changes: 10 additions & 0 deletions tezos/new_context/src/lib.rs
Expand Up @@ -35,6 +35,7 @@ pub use actions::ActionRecorder;
pub use hash::EntryHash;
pub use tezedge_context::TezedgeContext;
pub use tezedge_context::TezedgeIndex;
use working_tree::{working_tree::WorkingTree, NodeKind};

use crate::gc::GarbageCollector;
use crate::working_tree::working_tree::MerkleError;
Expand Down Expand Up @@ -88,6 +89,15 @@ where
fn mem(&self, key: &ContextKey) -> Result<bool, ContextError>;
// mem_tree - check if directory exists
fn mem_tree(&self, key: &ContextKey) -> bool;
fn find_tree(&self, key: &ContextKey) -> Result<Option<WorkingTree>, ContextError>;
fn add_tree(&self, key: &ContextKey, tree: &WorkingTree) -> Result<WorkingTree, ContextError>;
fn equal(&self, other: &Self) -> Result<bool, ContextError>;
fn hash(&self) -> Result<EntryHash, ContextError>;
fn kind(&self, key: &ContextKey) -> Result<NodeKind, ContextError>;
fn empty(&self) -> Self;
fn is_empty(&self) -> bool;
fn list(&self, key: &ContextKey);
fn fold(&self, key: &ContextKey);

fn get_merkle_root(&self) -> Result<EntryHash, ContextError>;
}
Expand Down
38 changes: 37 additions & 1 deletion tezos/new_context/src/tezedge_context.rs
Expand Up @@ -9,7 +9,7 @@ use std::{convert::TryFrom, rc::Rc};

use crypto::hash::ContextHash;

use crate::working_tree::working_tree_stats::MerkleStoragePerfReport;
use crate::working_tree::{working_tree_stats::MerkleStoragePerfReport, NodeKind};
use crate::{
hash::EntryHash,
working_tree::{Commit, Entry, Tree},
Expand Down Expand Up @@ -114,6 +114,42 @@ impl ProtocolContextApi for TezedgeContext {
self.tree.mem_tree(key)
}

fn find_tree(&self, key: &ContextKey) -> Result<Option<WorkingTree>, ContextError> {
self.tree.find_tree(key).map_err(Into::into)
}

fn add_tree(&self, key: &ContextKey, tree: &WorkingTree) -> Result<WorkingTree, ContextError> {
self.tree.add_tree(key, tree).map_err(Into::into)
}

fn equal(&self, other: &Self) -> Result<bool, ContextError> {
self.tree.equal(&other.tree).map_err(Into::into)
}

fn hash(&self) -> Result<EntryHash, ContextError> {
self.tree.hash().map_err(Into::into)
}

fn kind(&self, key: &ContextKey) -> Result<NodeKind, ContextError> {
self.tree.kind(key).map_err(Into::into)
}

fn empty(&self) -> Self {
self.with_tree(self.tree.empty())
}

fn is_empty(&self) -> bool {
self.tree.is_empty()
}

fn list(&self, key: &ContextKey) {
self.tree.list(key)
}

fn fold(&self, key: &ContextKey) {
self.tree.fold(key)
}

fn get_merkle_root(&self) -> Result<EntryHash, ContextError> {
Ok(self.tree.get_working_tree_root_hash()?)
}
Expand Down

0 comments on commit e9898b3

Please sign in to comment.