Skip to content

Commit 4864dae

Browse files
committed
fix(Blockchain): handle closed BlockStore when initializing
Fixes errors in the Blockchain tests.
1 parent 82634e4 commit 4864dae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/blockchain.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if (process.browser) {
1515
function noop () {}
1616

1717
var TIME_MARGIN = 2 * 60 * 60
18+
var storeClosedError = new Error('Store is closed')
1819

1920
var Blockchain = module.exports = function (opts) {
2021
var self = this
@@ -40,7 +41,8 @@ var Blockchain = module.exports = function (opts) {
4041

4142
this.store = opts.store || new BlockStore({ path: opts.path })
4243
this._initStore(function (err) {
43-
if (err) return self._error(err)
44+
if (err && err !== storeClosedError) return self._error(err)
45+
else if (err && err === storeClosedError) return
4446
self.initialized = true
4547
self.emit('ready')
4648
})
@@ -68,7 +70,7 @@ Blockchain.prototype._initStore = function (cb) {
6870
return function (cb) {
6971
self.store.get(block.hash, function (err) {
7072
if (err && !err.notFound) return cb(err)
71-
if (self.closed || self.store.isClosed()) return cb(new Error('Store is closed'))
73+
if (self.closed || self.store.isClosed()) return cb(storeClosedError)
7274
self.store.put(block, cb)
7375
})
7476
}

0 commit comments

Comments
 (0)