From 7d61cda3aa760904bca05cb9b4a11ad9bae6660c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 21 May 2017 18:40:43 -0700 Subject: [PATCH] chain/mempool: more aggressive asserts. --- lib/blockchain/chaindb.js | 13 ++++++------- lib/mempool/mempool.js | 12 +++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 525fce08..a387440d 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -1121,7 +1121,7 @@ ChainDB.prototype.getCoinsByAddress = co(function* getCoinsByAddress(addresses) hash = Address.getHash(address); if (!hash) - continue; + throw new Error('Not an address.'); keys = yield this.db.keys({ gte: layout.C(hash, encoding.ZERO_HASH, 0), @@ -1132,9 +1132,8 @@ ChainDB.prototype.getCoinsByAddress = co(function* getCoinsByAddress(addresses) for (j = 0; j < keys.length; j++) { key = keys[j]; coin = yield this.getCoin(key[0], key[1]); - - if (coin) - coins.push(coin); + assert(coin); + coins.push(coin); } } @@ -1160,7 +1159,7 @@ ChainDB.prototype.getHashesByAddress = co(function* getHashesByAddress(addresses hash = Address.getHash(address); if (!hash) - continue; + throw new Error('Not an address.'); yield this.db.keys({ gte: layout.T(hash, encoding.ZERO_HASH), @@ -1217,8 +1216,8 @@ ChainDB.prototype.getMetaByAddress = co(function* getTXByAddress(addresses) { for (i = 0; i < hashes.length; i++) { hash = hashes[i]; tx = yield this.getMeta(hash); - if (tx) - txs.push(tx); + assert(tx); + txs.push(tx); } return txs; diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index b7d11a1e..d7b5b0c2 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -554,7 +554,7 @@ Mempool.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) { hash = Address.getHash(addresses[i], 'hex'); if (!hash) - continue; + throw new Error('Not an address.'); coin = this.coinIndex.get(hash); @@ -582,7 +582,7 @@ Mempool.prototype.getTXByAddress = function getTXByAddress(addresses) { hash = Address.getHash(addresses[i], 'hex'); if (!hash) - continue; + throw new Error('Not an address.'); tx = this.txIndex.get(hash); @@ -610,7 +610,7 @@ Mempool.prototype.getMetaByAddress = function getMetaByAddress(addresses) { hash = Address.getHash(addresses[i], 'hex'); if (!hash) - continue; + throw new Error('Not an address.'); tx = this.txIndex.getMeta(hash); @@ -1428,8 +1428,7 @@ Mempool.prototype.getBalance = function getBalance() { hash = hashes[i]; tx = this.getTX(hash); - if (!tx) - continue; + assert(tx); hash = tx.hash('hex'); @@ -1457,8 +1456,7 @@ Mempool.prototype.getHistory = function getHistory() { hash = hashes[i]; tx = this.getTX(hash); - if (!tx) - continue; + assert(tx); txs.push(tx); }