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

Replace levelup+memdown with level-mem 3.0.1 and upgrade level-ws to 1.0.0 #56

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: node_js
node_js:
- "4"
- "5"
- "6"
- "7"
- "8"
- "9"
- "10"
env:
- CXX=g++-4.8
addons:
Expand Down Expand Up @@ -35,5 +33,3 @@ matrix:
env: CXX=g++-4.8 TEST_SUITE=test:browser
script: npm run $TEST_SUITE

notifications:
irc: "chat.freenode.net#ethereumjs"
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SYNOPSIS
# 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)
Expand All @@ -22,9 +22,9 @@ The only backing store supported is LevelDB through the ```levelup``` module.

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

trie.put('test', 'one', function () {
trie.get('test', function (err, value) {
Expand All @@ -49,19 +49,19 @@ Trie.prove(trie, 'test', function (err, prove) {
## Read stream on Geth DB

```javascript
var levelup = require('levelup')
var level = require('level')
var Trie = require('./secure')

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

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

trie.createReadStream()
.on('data', function (data) {
console.log(data)
})
.on('end', function() {
.on('end', function() {
console.log('End.')
})
```
Expand Down
10 changes: 3 additions & 7 deletions baseTrie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('assert')
const levelup = require('levelup')
const memdown = require('memdown')
const level = require('level-mem')
const async = require('async')
const rlp = require('rlp')
const ethUtil = require('ethereumjs-util')
Expand All @@ -19,7 +18,7 @@ module.exports = Trie
* Use `require('merkel-patricia-tree')` for the base interface. In Ethereum applications stick with the Secure Trie Overlay `require('merkel-patricia-tree/secure')`. The API for the raw and the secure interface are about the same
* @class Trie
* @param {Object} [db] An instance of [levelup](https://github.com/rvagg/node-levelup/) or a compatible API. If the db is `null` or left undefined, then the trie will be stored in memory via [memdown](https://github.com/rvagg/memdown)
* @param {Buffer|String} [root]` A hex `String` or `Buffer` for the root of a previously stored trie
* @param {Buffer|String} [root] A hex `String` or `Buffer` for the root of a previously stored trie
* @prop {Buffer} root The current root of the `trie`
* @prop {Boolean} isCheckpoint determines if you are saving to a checkpoint or directly to the db
* @prop {Buffer} EMPTY_TRIE_ROOT the Root for an empty trie
Expand All @@ -30,10 +29,7 @@ function Trie (db, root) {
this.sem = semaphore(1)

// setup dbs
this.db = db ||
levelup('', {
db: memdown
})
this.db = db || level()

this._getDBs = [this.db]
this._putDBs = [this.db]
Expand Down
15 changes: 4 additions & 11 deletions checkpoint-interface.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const levelup = require('levelup')
const memdown = require('memdown')
const level = require('level-mem')
const async = require('async')
const inherits = require('util').inherits
const Readable = require('readable-stream').Readable
const levelws = require('level-ws')
const WriteStream = require('level-ws')
const callTogether = require('./util').callTogether

module.exports = checkpointInterface
Expand Down Expand Up @@ -90,9 +89,7 @@ function revert (cb) {

// enter into checkpoint mode
function _enterCpMode () {
this._scratch = levelup('', {
db: memdown
})
this._scratch = level()
this._getDBs = [this._scratch].concat(this._getDBs)
this.__putDBs = this._putDBs
this._putDBs = [this._scratch]
Expand All @@ -110,12 +107,8 @@ function _exitCpMode (commitState, cb) {
this.putRaw = this._putRaw

function flushScratch (db, cb) {
if (!db.createWriteStream) {
db = levelws(db)
}

self.createScratchReadStream(scratch)
.pipe(db.createWriteStream())
.pipe(WriteStream(db))
.on('close', cb)
}

Expand Down
Loading