Skip to content

Commit

Permalink
remove dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Josiah Evans committed Dec 20, 2018
1 parent f74c90a commit 0dbcda4
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 1,211 deletions.
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
[package]
name = "starling"
version = "1.0.3"
version = "1.0.4"
authors = ["Josiah Evans <koreanhalo@gmail.com>"]
description = "This tree structure is a binary merkle tree with branch compression via split indexes."
repository = "https://github.com/ChosunOne/merkle_bit"
keywords = ["binary", "merkle", "tree", "patricia"]
license = "MIT"
readme = "README.md"

[build-dependencies]
protoc-rust-no-elision = "2.0.4"

[dev-dependencies]
protobuf-codegen-no-elision = "2.0.4"
protoc = "2.0.4"
blake2-rfc = "0.2.18"
protobuf = "2.0.4"
rand = "0.5.5"

[dependencies]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This tree structure is a binary merkle tree with branch compression via split in
## Basic Usage
```rust
extern crate starling;
use starling::common::merkle_bit::MerkleBIT;
use starling::merkle_bit::MerkleBIT;
use std::path::PathBuf;

fn main() {
Expand All @@ -22,7 +22,7 @@ This tree structure is a binary merkle tree with branch compression via split in
HashResultType,
ValueType>::new(path, 8);

// Keys must by slices of u8 arrays or vectors
// Keys must be slices of u8 arrays or vectors
let key: Vec<u8> = vec![0x00u8, 0x81u8, 0xA3u8];

// An example value created from ValueType.
Expand Down
16 changes: 0 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
extern crate protoc_rust_no_elision;

fn main() {
build_proto();
}

fn build_proto() {
println!("Building...");
protoc_rust_no_elision::run(protoc_rust_no_elision::Args {
out_dir: "src/serialization",
input: &[
"src/proto/state.proto",
],
includes: &["src/proto/"],
customize: protoc_rust_no_elision::Customize {
..Default::default()
},
}).expect("protoc");
}
44 changes: 0 additions & 44 deletions src/common/mod.rs

This file was deleted.

5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(test)] extern crate blake2_rfc;
#[cfg(test)] extern crate protobuf;
#[cfg(test)] extern crate rand;

pub mod common;
#[cfg(test)] pub mod serialization;
pub mod merkle_bit;
pub mod traits;
162 changes: 146 additions & 16 deletions src/common/merkle_bit.rs → src/merkle_bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use std::hash::Hash;
use std::cmp::Ordering;
use std::marker::PhantomData;


use common::{Encode, Exception, Decode};
use common::traits::{Branch, Data, Hasher, IDB, Node, Leaf};
use traits::{Encode, Exception, Decode, Branch, Data, Hasher, IDB, Node, Leaf};

/// A generic Result from an operation involving a MerkleBIT
pub type BinaryMerkleTreeResult<T> = Result<T, Box<Error>>;

/// Contains the distinguishing data from the node
#[derive(Clone)]
pub enum NodeVariant<BranchType, LeafType, DataType>
where BranchType: Branch,
LeafType: Leaf,
Expand Down Expand Up @@ -723,16 +722,8 @@ impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, HashRes
#[cfg(test)]
pub mod tests {
use super::*;
use serialization::state::{MerkleNode as ProtoMerkleNode,
MerkleNode_oneof_node::branch as ProtoMerkleNodeBranch,
MerkleNode_oneof_node::data as ProtoMerkleNodeData,
MerkleNode_oneof_node::leaf as ProtoMerkleNodeLeaf,
Branch as ProtoBranch,
Leaf as ProtoLeaf,
Data as ProtoData};

use blake2_rfc::blake2b::{blake2b, Blake2b, Blake2bResult};
use protobuf::Message as ProtoMessage;
use std::collections::HashMap;
use rand::{Rng, SeedableRng, StdRng};

Expand Down Expand Up @@ -767,7 +758,8 @@ pub mod tests {

fn get_node(&self, key: &[u8]) -> Result<Option<Self::NodeType>, Box<Error>> {
if let Some(m) = self.map.get(key) {
return Ok(Some(m.clone()))
let node = m.clone();
return Ok(Some(node))
} else {
return Ok(None)
}
Expand Down Expand Up @@ -808,6 +800,145 @@ pub mod tests {
}
}

#[derive(Clone)]
struct ProtoBranch {
count: u64,
zero: Vec<u8>,
one: Vec<u8>,
split_index: u32
}

impl ProtoBranch {
fn new() -> ProtoBranch {
ProtoBranch {
count: 0,
zero: vec![],
one: vec![],
split_index: 0
}
}

fn get_count(&self) -> u64 {
self.count
}

fn get_zero(&self) -> &[u8] {
self.zero.as_ref()
}

fn get_one(&self) -> &[u8] {
self.one.as_ref()
}

fn get_split_index(&self) -> u32 {
self.split_index
}

fn set_count(&mut self, count: u64) {
self.count = count;
}

fn set_zero(&mut self, zero: Vec<u8>) {
self.zero = zero;
}

fn set_one(&mut self, one: Vec<u8>) {
self.one = one;
}

fn set_split_index(&mut self, split_index: u32) {
self.split_index = split_index;
}
}

#[derive(Clone)]
struct ProtoLeaf {
key: Vec<u8>,
data: Vec<u8>
}

impl ProtoLeaf {
fn new() -> ProtoLeaf {
ProtoLeaf {
key: vec![],
data: vec![]
}
}

fn get_key(&self) -> &[u8] {
self.key.as_ref()
}

fn get_data(&self) -> &[u8] {
self.data.as_ref()
}

fn set_key(&mut self, key: Vec<u8>) {
self.key = key;
}

fn set_data(&mut self, data: Vec<u8>) {
self.data = data;
}
}

#[derive(Clone)]
struct ProtoData {
value: Vec<u8>
}

impl ProtoData {
fn new() -> ProtoData {
ProtoData {
value: vec![]
}
}

fn get_value(&self) -> &[u8] {
self.value.as_ref()
}

fn set_value(&mut self, value: Vec<u8>) {
self.value = value;
}
}

#[derive(Clone)]
struct ProtoMerkleNode {
references: u64,
node: Option<NodeVariant<ProtoBranch, ProtoLeaf, ProtoData>>
}

impl ProtoMerkleNode {
fn new() -> ProtoMerkleNode {
ProtoMerkleNode {
references: 0,
node: None
}
}

fn get_references(&self) -> u64 {
self.references
}

fn set_references(&mut self, references: u64) {
self.references = references;
}

fn set_branch(&mut self, branch: ProtoBranch) {
self.node = Some(NodeVariant::Branch(branch));
}

fn set_leaf(&mut self, leaf: ProtoLeaf) {
self.node = Some(NodeVariant::Leaf(leaf));
}

fn set_data(&mut self, data: ProtoData) {
self.node = Some(NodeVariant::Data(data));
}

}

impl Branch for ProtoBranch {
fn new() -> ProtoBranch {
ProtoBranch::new()
Expand Down Expand Up @@ -886,9 +1017,9 @@ pub mod tests {
match self.node {
Some(ref node_type) => {
match node_type {
ProtoMerkleNodeBranch(branch) => return Ok(NodeVariant::Branch(branch.clone())),
ProtoMerkleNodeData(data) => return Ok(NodeVariant::Data(data.clone())),
ProtoMerkleNodeLeaf(leaf) => return Ok(NodeVariant::Leaf(leaf.clone()))
NodeVariant::Branch(branch) => return Ok(NodeVariant::Branch(branch.clone())),
NodeVariant::Data(data) => return Ok(NodeVariant::Data(data.clone())),
NodeVariant::Leaf(leaf) => return Ok(NodeVariant::Leaf(leaf.clone()))
}
},
None => return Err(Box::new(Exception::new("Failed to distinguish node type")))
Expand Down Expand Up @@ -918,7 +1049,6 @@ pub mod tests {
impl Decode for ProtoMerkleNode {
fn decode(buffer: &[u8]) -> Result<ProtoMerkleNode, Box<Error>> {
let mut proto = ProtoMerkleNode::new();
proto.merge_from_bytes(buffer)?;
Ok(proto)
}
}
Expand Down
26 changes: 0 additions & 26 deletions src/proto/state.proto

This file was deleted.

1 change: 0 additions & 1 deletion src/serialization/mod.rs

This file was deleted.

Loading

0 comments on commit 0dbcda4

Please sign in to comment.