diff --git a/README.md b/README.md index 7e63ce3..cba6944 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/index.js b/index.js index 6fa9f90..2d5ba7c 100644 --- a/index.js +++ b/index.js @@ -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') @@ -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 = {} @@ -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() } } @@ -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) diff --git a/package.json b/package.json index 0313809..4d0dc35 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/index.js b/test/index.js index a87d930..ebba9d2 100644 --- a/test/index.js +++ b/test/index.js @@ -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 @@ -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}) @@ -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) @@ -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'),