mirror of
https://github.com/zaphar/merkle-dag.git
synced 2025-07-21 18:19:58 -04:00
Formatting and docstrings
This commit is contained in:
parent
6e40f07f28
commit
45486b5cc7
@ -11,6 +11,9 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! Implements the HashWriter interface for the Blake2 hash function.
|
||||
//! Requires the `blake2` feature to be set.
|
||||
|
||||
use crate::hash::*;
|
||||
use blake2::digest::Digest;
|
||||
pub use blake2::{Blake2b512, Blake2s256};
|
||||
|
@ -11,6 +11,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! Implementation of the MerkleDag based off of the merkle-crdt whitepaper.
|
||||
|
||||
use std::{collections::BTreeSet, marker::PhantomData};
|
||||
|
||||
@ -68,8 +69,8 @@ where
|
||||
/// and add it to the DAG with the given payload item and dependency id set. It is idempotent for any
|
||||
/// given set of inputs.
|
||||
///
|
||||
/// One result of not constructing/adding nodes in this way is that we ensure that we always satisfy
|
||||
/// the implementation rule in the merkel-crdt's whitepaper.
|
||||
/// One result of not constructing and then adding nodes in this way is that we ensure that we always
|
||||
/// satisfy the implementation rule in the merkel-crdt's whitepaper.
|
||||
pub fn add_node<'a, N: Into<Vec<u8>>>(
|
||||
&'a mut self,
|
||||
item: N,
|
||||
|
@ -11,6 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! HashWriter trait specification and default implementations.
|
||||
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hasher;
|
||||
|
||||
|
@ -11,6 +11,9 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! Module implementing a store interface using LevelDB for a MerkleDag.
|
||||
//! Requires the `rusty-leveldb` interface.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
|
||||
@ -23,8 +26,9 @@ use crate::blake2::*;
|
||||
use ciborium;
|
||||
use rusty_leveldb;
|
||||
|
||||
// TODO(jwall): Add leveldb backing store for a Merkle-DAG
|
||||
|
||||
/// A `Store` implementation using the rusty-leveldb port of leveldb.
|
||||
/// The Default implementation of this `Default::default()` is an in-memory
|
||||
/// implementation of the store.
|
||||
pub struct LevelStore {
|
||||
store: RefCell<rusty_leveldb::DB>,
|
||||
}
|
||||
@ -37,6 +41,7 @@ impl LevelStore {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Store<Blake2b512> for LevelStore {
|
||||
fn contains(&self, id: &[u8]) -> Result<bool> {
|
||||
Ok(self.store.borrow_mut().get(id).is_some())
|
||||
|
@ -11,6 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! A merkle dag along the lines of the merkle-crdt whitepaper.
|
||||
|
||||
#[cfg(feature = "blake2")]
|
||||
pub mod blake2;
|
||||
pub mod dag;
|
||||
|
@ -11,6 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! `Node` types for satisfying the properties necessary for a MerkleDag.
|
||||
|
||||
use std::{collections::BTreeSet, marker::PhantomData};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -11,7 +11,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Exports the most common set of types for this crate.
|
||||
pub use crate::dag::*;
|
||||
pub use crate::hash::*;
|
||||
pub use crate::node::*;
|
||||
|
@ -11,6 +11,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//! The MerkleDag backing store trait.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{hash::HashWriter, node::Node};
|
||||
@ -23,12 +25,16 @@ pub enum StoreError {
|
||||
NoSuchDependents,
|
||||
}
|
||||
|
||||
/// Trait representing the backing storage interface for a `DAG`.
|
||||
pub trait Store<HW>: Default
|
||||
where
|
||||
HW: HashWriter,
|
||||
{
|
||||
/// Checks if the `Store` contains a node with this id.
|
||||
fn contains(&self, id: &[u8]) -> Result<bool>;
|
||||
/// Fetches a node from the `Store` by id if it exists.
|
||||
fn get(&self, id: &[u8]) -> Result<Option<Node<HW>>>;
|
||||
/// Stores a given node.
|
||||
fn store(&mut self, node: Node<HW>) -> Result<()>;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user