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

Commit f96aa9a

Browse files
authored
Merge pull request #75 from pzagor2/updading-levelup
Updating levelup dependency
2 parents a0581ef + ade93e5 commit f96aa9a

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ A module to store and interact with blocks.
1111

1212
# EXAMPLE
1313

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

1717
```javascript
18-
const levelup = require('levelup')
19-
const leveldown = require('leveldown')
18+
const level = require('level')
2019
const Blockchain = require('ethereumjs-blockchain')
2120
const utils = require('ethereumjs-util')
2221

2322
const gethDbPath = './chaindata' // Add your own path here
24-
const db = levelup(gethDbPath, { db: leveldown })
23+
const db = level(gethDbPath)
2524

2625
new Blockchain({db: db}).iterator('i', (block, reorg, cb) => {
2726
const blockNumber = utils.bufferToInt(block.header.number)

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const async = require('async')
44
const Stoplight = require('flow-stoplight')
55
const semaphore = require('semaphore')
6-
const levelup = require('levelup')
7-
const memdown = require('memdown')
6+
const level = require('level-mem')
87
const Block = require('ethereumjs-block')
98
const Common = require('ethereumjs-common')
109
const ethUtil = require('ethereumjs-util')
@@ -55,7 +54,7 @@ function Blockchain (opts) {
5554
self.db = opts.db || opts.blockDb
5655

5756
// defaults
58-
self.db = self.db ? self.db : levelup('', { db: memdown })
57+
self.db = self.db ? self.db : level()
5958
self.validate = (opts.validate === undefined ? true : opts.validate)
6059
self.ethash = self.validate ? new Ethash(self.db) : null
6160
self._heads = {}
@@ -938,7 +937,7 @@ Blockchain.prototype._iterator = function (name, func, cb) {
938937
} else {
939938
blockNumber = false
940939
// No more blocks, return
941-
if (err instanceof levelup.errors.NotFoundError) {
940+
if (err instanceof level.errors.NotFoundError) {
942941
return cb2()
943942
}
944943
}
@@ -1001,7 +1000,7 @@ Blockchain.prototype._numberToHash = function (number, cb) {
10011000
const self = this
10021001

10031002
if (number.ltn(0)) {
1004-
return cb(new levelup.errors.NotFoundError())
1003+
return cb(new level.errors.NotFoundError())
10051004
}
10061005
var key = numberToHashKey(number)
10071006
var hash = self._cache.numberToHash.get(key)

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
"ethereumjs-common": "~0.6.0",
3131
"ethereumjs-util": "~6.0.0",
3232
"flow-stoplight": "^1.0.0",
33-
"levelup": "^1.3.2",
33+
"level-mem": "^3.0.1",
3434
"lru-cache": "^4.1.3",
35-
"memdown": "^1.1.0",
3635
"safe-buffer": "^5.1.2",
3736
"semaphore": "^1.1.0"
3837
},

test/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const Block = require('ethereumjs-block')
66
const Common = require('ethereumjs-common')
77
const async = require('async')
88
const ethUtil = require('ethereumjs-util')
9-
const levelup = require('levelup')
10-
const memdown = require('memdown')
9+
const level = require('level-mem')
1110
const testData = require('./testdata.json')
1211
const BN = require('bn.js')
1312
const rlp = ethUtil.rlp
@@ -45,7 +44,7 @@ test('blockchain test', function (t) {
4544
})
4645
},
4746
function alternateConstructors (done) {
48-
var db = levelup('', { db: memdown })
47+
var db = level()
4948
var blockchain = new Blockchain(db)
5049
t.equals(db, blockchain.db, 'support constructor with db parameter')
5150
blockchain = new Blockchain({detailsDb: db, blockDb: db})
@@ -375,7 +374,7 @@ test('blockchain test', function (t) {
375374
})
376375
},
377376
function saveHeads (done) {
378-
var db = levelup('', { db: memdown })
377+
var db = level()
379378
var blockchain = new Blockchain({db: db, validate: false})
380379
var header = new Block.Header()
381380
header.number = ethUtil.toBuffer(1)
@@ -523,7 +522,7 @@ function isConsecutive (blocks) {
523522
function createTestDB (cb) {
524523
var genesis = new Block()
525524
genesis.setGenesisParams()
526-
var db = levelup('', { db: memdown })
525+
var db = level()
527526
db.batch([{
528527
type: 'put',
529528
key: Buffer.from('6800000000000000006e', 'hex'),

0 commit comments

Comments
 (0)