Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge c693c65 into 5a5b1a1
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Aug 5, 2019
2 parents 5a5b1a1 + c693c65 commit 2470d08
Show file tree
Hide file tree
Showing 43 changed files with 716 additions and 593 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

15 changes: 2 additions & 13 deletions .gitignore
@@ -1,16 +1,5 @@
package-lock.json
node_modules
dist/

/baseTrie.js
/checkpointTrie.js
/db.js
/index.js
/prioritizedTaskExecutor.js
/proof.js
/readStream.js
/scratch.js
/scratchReadStream.js
/secure.js
/trieNode.js
/util/
.nyc_output
coverage
10 changes: 10 additions & 0 deletions .nycrc
@@ -0,0 +1,10 @@
{
"extends": "@ethereumjs/config-nyc",
"include": [
"dist/**/*.js"
],
"extension": [
".js"
],
"source-map": false
}
7 changes: 7 additions & 0 deletions .prettierignore
@@ -0,0 +1,7 @@
node_modules
.vscode
package.json
dist
.nyc_output
*.json
docs
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -31,5 +31,5 @@ matrix:
- os: linux
node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=test:browser
script: npm run $TEST_SUITE
script: npm run build && npm run $TEST_SUITE

40 changes: 23 additions & 17 deletions CHANGELOG.md
@@ -1,67 +1,73 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
(modification: no type change headlines) and this project adheres to
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
(modification: no type change headlines) and this project adheres to
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2019-01-03

This release comes along with some major version bump of the underlying ``level``
database storage backend. If you have the library deeper integrated in one of
This release comes along with some major version bump of the underlying `level`
database storage backend. If you have the library deeper integrated in one of
your projects make sure that the new DB version plays well with the rest of the
code.

The release also introduces modern ``ES6`` JavaScript for the library (thanks @alextsg)
switching to ``ES6`` classes and clean inheritance on all the modules.
The release also introduces modern `ES6` JavaScript for the library (thanks @alextsg)
switching to `ES6` classes and clean inheritance on all the modules.

- Replace ``levelup`` 1.2.1 + ``memdown`` 1.0.0 with ``level-mem`` 3.0.1 and upgrade ``level-ws`` to 1.0.0, PR [#56](https://github.com/ethereumjs/merkle-patricia-tree/pull/56)
- Support for ``ES6`` classes, PRs [#57](https://github.com/ethereumjs/merkle-patricia-tree/pull/57), [#61](https://github.com/ethereumjs/merkle-patricia-tree/pull/61)
- Updated ``async`` and ``readable-stream`` dependencies (resulting in smaller browser builds), PR [#60](https://github.com/ethereumjs/merkle-patricia-tree/pull/60)
- Replace `levelup` 1.2.1 + `memdown` 1.0.0 with `level-mem` 3.0.1 and upgrade `level-ws` to 1.0.0, PR [#56](https://github.com/ethereumjs/merkle-patricia-tree/pull/56)
- Support for `ES6` classes, PRs [#57](https://github.com/ethereumjs/merkle-patricia-tree/pull/57), [#61](https://github.com/ethereumjs/merkle-patricia-tree/pull/61)
- Updated `async` and `readable-stream` dependencies (resulting in smaller browser builds), PR [#60](https://github.com/ethereumjs/merkle-patricia-tree/pull/60)
- Updated, automated and cleaned up [API documentation](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/docs/index.md) build, PR [#63](https://github.com/ethereumjs/merkle-patricia-tree/pull/63)

[3.0.0]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.3.2...v3.0.0

## [2.3.2] - 2018-09-24

- Fixed a bug in verify proof if the tree contains an extension node with an embedded branch node, PR [#51](https://github.com/ethereumjs/merkle-patricia-tree/pull/51)
- Fixed ``_scratch`` 'leak' to global/window, PR [#42](https://github.com/ethereumjs/merkle-patricia-tree/pull/42)
- Fixed `_scratch` 'leak' to global/window, PR [#42](https://github.com/ethereumjs/merkle-patricia-tree/pull/42)
- Fixed coverage report leaving certain tests, PR [#53](https://github.com/ethereumjs/merkle-patricia-tree/pull/53)

[2.3.2]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.3.1...v2.3.2

## [2.3.1] - 2018-03-14
- Fix OutOfMemory bug when trying to create a read stream on large trie structures

- Fix OutOfMemory bug when trying to create a read stream on large trie structures
(e.g. a current state DB from a Geth node), PR [#38](https://github.com/ethereumjs/merkle-patricia-tree/pull/38)
- Fix race condition due to mutated ``_getDBs``/``_putDBs``, PR [#28](https://github.com/ethereumjs/merkle-patricia-tree/pull/28)
- Fix race condition due to mutated `_getDBs`/`_putDBs`, PR [#28](https://github.com/ethereumjs/merkle-patricia-tree/pull/28)

[2.3.1]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.3.0...v2.3.1

## [2.3.0] - 2017-11-30
- Methods for merkle proof generation ``Trie.prove()`` and verification ``Trie.verifyProof()`` (see [./proof.js](./proof.js))

- Methods for merkle proof generation `Trie.prove()` and verification `Trie.verifyProof()` (see [./proof.js](./proof.js))

[2.3.0]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.2.0...v2.3.0

## [2.2.0] - 2017-08-03
- Renamed ``root`` functions argument to ``nodeRef`` for passing a node reference
- Make ``findPath()`` (path to node for given key) a public method

- Renamed `root` functions argument to `nodeRef` for passing a node reference
- Make `findPath()` (path to node for given key) a public method

[2.2.0]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.1.2...v2.2.0

## [2.1.2] - 2016-03-01

- Added benchmark (see [./benchmarks/](./benchmarks/))
- Updated dependencies

[2.1.2]: https://github.com/ethereumjs/merkle-patricia-tree/compare/v2.1.1...v2.1.2

## [2.1.1] - 2016-01-06

- Added README, API documentation
- Dependency updates

[2.1.1]: https://github.com/ethereumjs/merkle-patricia-tree/compare/2.0.3...v2.1.1

## [2.0.3] - 2015-09-24

- Initial, first of the currently released version on npm

[2.0.3]: https://github.com/ethereumjs/merkle-patricia-tree/compare/1.1.x...2.0.3


63 changes: 35 additions & 28 deletions README.md
@@ -1,44 +1,46 @@
# SYNOPSIS

[![NPM Package](https://img.shields.io/npm/v/merkle-patricia-tree.svg?style=flat-square)](https://www.npmjs.org/package/merkle-patricia-tree)
[![Build Status](https://img.shields.io/travis/ethereumjs/merkle-patricia-tree.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/merkle-patricia-tree)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/merkle-patricia-tree.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/merkle-patricia-tree)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

This is an implementation of the modified merkle patricia tree as specified in the [Ethereum's yellow paper](http://gavwood.com/Paper.pdf).

> The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification is to provide a single 32-byte value that identifies a given set of key-value pairs.
\- Ethereum's yellow paper
> The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification is to provide a single 32-byte value that identifies a given set of key-value pairs.
> \- Ethereum's yellow paper
The only backing store supported is LevelDB through the ```levelup``` module.
The only backing store supported is LevelDB through the `levelup` module.

# INSTALL
`npm install merkle-patricia-tree`

`npm install merkle-patricia-tree`

# USAGE

## Initialization and Basic Usage

```javascript
var Trie = require('merkle-patricia-tree'),
level = require('level'),
db = level('./testdb'),
trie = new Trie(db);

trie.put('test', 'one', function () {
trie.get('test', function (err, value) {
if(value) console.log(value.toString())
});
});
level = require('level'),
db = level('./testdb'),
trie = new Trie(db)

trie.put('test', 'one', function() {
trie.get('test', function(err, value) {
if (value) console.log(value.toString())
})
})
```

## Merkle Proofs

```javascript
Trie.prove(trie, 'test', function (err, prove) {
Trie.prove(trie, 'test', function(err, prove) {
if (err) return cb(err)
Trie.verifyProof(trie.root, 'test', prove, function (err, value) {
Trie.verifyProof(trie.root, 'test', prove, function(err, value) {
if (err) return cb(err)
console.log(value.toString())
cb()
Expand All @@ -52,13 +54,14 @@ Trie.prove(trie, 'test', function (err, prove) {
var level = require('level')
var Trie = require('./secure')

var stateRoot = "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544" // Block #222
var stateRoot = '0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544' // Block #222

var db = level('YOUR_PATH_TO_THE_GETH_CHAIN_DB')
var trie = new Trie(db, stateRoot)

trie.createReadStream()
.on('data', function (data) {
trie
.createReadStream()
.on('data', function(data) {
console.log(data)
})
.on('end', function() {
Expand All @@ -84,7 +87,7 @@ var trie = new Trie(db, stateRoot)

var address = 'AN_ETHEREUM_ACCOUNT_ADDRESS'

trie.get(address, function (err, data) {
trie.get(address, function(err, data) {
if (err) return cb(err)

var acc = new Account(data)
Expand All @@ -99,20 +102,23 @@ trie.get(address, function (err, data) {

console.log('------Storage------')
var stream = storageTrie.createReadStream()
stream.on('data', function(data) {
console.log(`key: ${ethutil.bufferToHex(data.key)}`)
console.log(`Value: ${ethutil.bufferToHex(rlp.decode(data.value))}`)
})
.on('end', function() {
console.log('Finished reading storage.')
})
stream
.on('data', function(data) {
console.log(`key: ${ethutil.bufferToHex(data.key)}`)
console.log(`Value: ${ethutil.bufferToHex(rlp.decode(data.value))}`)
})
.on('end', function() {
console.log('Finished reading storage.')
})
})
```

# API

[./docs/](./docs/index.md)

# TESTING

`npm test`

# REFERENCES
Expand All @@ -130,4 +136,5 @@ See our organizational [documentation](https://ethereumjs.readthedocs.io) for an
If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html).

# LICENSE

MPL-2.0
18 changes: 0 additions & 18 deletions documentation.yml

This file was deleted.

38 changes: 8 additions & 30 deletions karma.conf.js
@@ -1,41 +1,19 @@
process.env.ethTest = 'TrieTests'

module.exports = function (config) {
module.exports = function(config) {
config.set({
browserNoActivityTimeout: 120000,
browserNoActivityTimeout: 60000,
frameworks: ['browserify', 'detectBrowsers', 'tap'],
files: [
'./test/*.js'
],
files: ['./test/*.js'],
preprocessors: {
'test/*.js': ['browserify', 'env']
'./dist/**/*.js': ['browserify'],
'./test/**/*.js': ['browserify']
},
singleRun: true,
plugins: [
'karma-browserify',
'karma-chrome-launcher',
'karma-env-preprocessor',
'karma-tap',
'karma-firefox-launcher',
'karma-detect-browsers'
],
browserify: {
debug: true,
transform: ['babelify']
},
detectBrowsers: {
enabled: true,
usePhantomJS: false,
postDetection: function (availableBrowser) {
if (process.env.TRAVIS) {
return ['Firefox']
}

var browsers = ['Chrome', 'Firefox']
return browsers.filter(function (browser) {
return availableBrowser.indexOf(browser) !== -1
})
}
postDetection: function(availableBrowsers) {
return ['Firefox']
},
}
})
}

0 comments on commit 2470d08

Please sign in to comment.