Git Product home page Git Product logo

rust-merkle-trie's Introduction

Merkle-Trie License: AGPL v3

The merkle trie used by CodeChain and Foundry.

Usage

The rust-merkle-trie crate provides merkle trie implementations. CodeChain and Foundry use a merkle trie to hold the states with authentication. We differ from the merkle patricia trie in Ethereum; details can be found here.

Let's use the merkle trie to show an example:

use merkle_trie::{Trie, TrieFactory, TrieMut};
use cdb::MemoryDB;
use primitives::H256;

// initialize
let mut memdb = MemoryDB::new();
let mut root = H256::zero();
let mut trie = TrieDBMut::new(&mut memdb, &mut root);

// insert
trie.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
assert_eq!(*trie.root(), trie_root(vec![(vec![0x01u8, 0x23], vec![0x01u8, 0x23])]));

// get
assert_eq!(trie.get(&0x01u8, 0x23]).unwrap().unwrap(), vec!0x01u8, 0x23]);
assert_eq!(t.get(&[0x02u8]), Ok(None));

// remove
trie.remove(&0x01u8, 0x23]).unwrap();
assert_eq!(t.get(&0x01u8, 0x23]), Ok(None));

Build

Download foundry code

git clone [email protected]:CodeChain-io/rust-merkle-trie.git
cd rust-merkle-trie

Build in debug mode

cargo build

Test

Developers are strongly encouraged to write unit tests for new code, and to submit new unit tests for old code. Unit tests can be compiled and run with: cargo test --all. For more details, please refer to Unit Tests.

Benchmark

Official documentation for usage of cargo bench:
https://doc.rust-lang.org/1.15.1/book/benchmark-tests.html

We can run the benchmark test with cargo bench:

cargo bench

rust-merkle-trie's People

Contributors

junha1 avatar majecty avatar

Stargazers

Seung Heo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.