Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Updating levelup dependency #75

Merged
merged 1 commit into from
Nov 4, 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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ A module to store and interact with blocks.

# EXAMPLE

The following is an example to iterate through an existing Geth DB (needs ``leveldown`` to be
The following is an example to iterate through an existing Geth DB (needs ``level`` to be
installed separately):

```javascript
const levelup = require('levelup')
const leveldown = require('leveldown')
const level = require('level')
const Blockchain = require('ethereumjs-blockchain')
const utils = require('ethereumjs-util')

const gethDbPath = './chaindata' // Add your own path here
const db = levelup(gethDbPath, { db: leveldown })
const db = level(gethDbPath)

new Blockchain({db: db}).iterator('i', (block, reorg, cb) => {
const blockNumber = utils.bufferToInt(block.header.number)
Expand Down
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
const async = require('async')
const Stoplight = require('flow-stoplight')
const semaphore = require('semaphore')
const levelup = require('levelup')
const memdown = require('memdown')
const level = require('level-mem')
const Block = require('ethereumjs-block')
const Common = require('ethereumjs-common')
const ethUtil = require('ethereumjs-util')
Expand Down Expand Up @@ -55,7 +54,7 @@ function Blockchain (opts) {
self.db = opts.db || opts.blockDb

// defaults
self.db = self.db ? self.db : levelup('', { db: memdown })
self.db = self.db ? self.db : level()
self.validate = (opts.validate === undefined ? true : opts.validate)
self.ethash = self.validate ? new Ethash(self.db) : null
self._heads = {}
Expand Down Expand Up @@ -938,7 +937,7 @@ Blockchain.prototype._iterator = function (name, func, cb) {
} else {
blockNumber = false
// No more blocks, return
if (err instanceof levelup.errors.NotFoundError) {
if (err instanceof level.errors.NotFoundError) {
return cb2()
}
}
Expand Down Expand Up @@ -1001,7 +1000,7 @@ Blockchain.prototype._numberToHash = function (number, cb) {
const self = this

if (number.ltn(0)) {
return cb(new levelup.errors.NotFoundError())
return cb(new level.errors.NotFoundError())
}
var key = numberToHashKey(number)
var hash = self._cache.numberToHash.get(key)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
"ethereumjs-common": "~0.6.0",
"ethereumjs-util": "~6.0.0",
"flow-stoplight": "^1.0.0",
"levelup": "^1.3.2",
"level-mem": "^3.0.1",
"lru-cache": "^4.1.3",
"memdown": "^1.1.0",
"safe-buffer": "^5.1.2",
"semaphore": "^1.1.0"
},
Expand Down
9 changes: 4 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const Block = require('ethereumjs-block')
const Common = require('ethereumjs-common')
const async = require('async')
const ethUtil = require('ethereumjs-util')
const levelup = require('levelup')
const memdown = require('memdown')
const level = require('level-mem')
const testData = require('./testdata.json')
const BN = require('bn.js')
const rlp = ethUtil.rlp
Expand Down Expand Up @@ -45,7 +44,7 @@ test('blockchain test', function (t) {
})
},
function alternateConstructors (done) {
var db = levelup('', { db: memdown })
var db = level()
var blockchain = new Blockchain(db)
t.equals(db, blockchain.db, 'support constructor with db parameter')
blockchain = new Blockchain({detailsDb: db, blockDb: db})
Expand Down Expand Up @@ -375,7 +374,7 @@ test('blockchain test', function (t) {
})
},
function saveHeads (done) {
var db = levelup('', { db: memdown })
var db = level()
var blockchain = new Blockchain({db: db, validate: false})
var header = new Block.Header()
header.number = ethUtil.toBuffer(1)
Expand Down Expand Up @@ -523,7 +522,7 @@ function isConsecutive (blocks) {
function createTestDB (cb) {
var genesis = new Block()
genesis.setGenesisParams()
var db = levelup('', { db: memdown })
var db = level()
db.batch([{
type: 'put',
key: Buffer.from('6800000000000000006e', 'hex'),
Expand Down