diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 1d7d8d27..f74c50f5 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -1502,7 +1502,8 @@ Mempool.prototype.isDoubleSpend = function isDoubleSpend(tx) { * @returns {Promise} - Returns {@link CoinView}. */ -Mempool.prototype._getCoinView = co(function* getCoinView(tx) { +Mempool.prototype.getCoinView = co(function* getCoinView(tx) { + var state = this.chain.state; var view = new CoinView(); var prevout = tx.getPrevout(); var i, entry, hash, coins; @@ -1528,6 +1529,9 @@ Mempool.prototype._getCoinView = co(function* getCoinView(tx) { view.add(coins); } + if (state !== this.chain.state) + throw new Error('Chain state changed while getting coins.'); + return view; }); @@ -1538,8 +1542,9 @@ Mempool.prototype._getCoinView = co(function* getCoinView(tx) { * @returns {Promise} - Returns {@link CoinView}. */ -Mempool.prototype.getCoinView = co(function* getCoinView(tx) { - var view = yield this.chain.getCoinView(tx); +Mempool.prototype._getCoinView = co(function* getCoinView(tx) { + var state = this.chain.state; + var view = yield this.chain.db.getCoinView(tx); var items = view.toArray(); var i, coins, entry; @@ -1557,6 +1562,9 @@ Mempool.prototype.getCoinView = co(function* getCoinView(tx) { view.addTX(entry.tx, -1); } + if (state !== this.chain.state) + throw new Error('Chain state changed while getting coins.'); + return view; });