From 9b90111a0a80fe8dcb0362c03777eeb4faface76 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 11 Mar 2016 22:58:01 -0800 Subject: [PATCH] refactor. --- lib/bcoin/chaindb.js | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index fefdf503..0db97516 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -1263,8 +1263,6 @@ ChainDB.prototype.isUnspentTX = function isUnspentTX(hash, callback) { }; ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { - var spent = true; - if (hash.hash) hash = hash.hash('hex'); @@ -1277,29 +1275,19 @@ ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { keyAsBuffer: false }); - (function next() { - iter.next(function(err, key, value) { - if (err) { - return iter.end(function() { - done(err); - }); - } + iter.next(function(err, key, value) { + if (err) { + return iter.end(function() { + callback(err); + }); + } - if (key === undefined) - return iter.end(done); - - spent = false; - - iter.end(done); + iter.end(function(err) { + if (err) + return callback(err); + return callback(null, key === undefined); }); - })(); - - function done(err) { - if (err) - return callback(err); - - return callback(null, spent); - } + }); }; ChainDB.prototype.hasTX = function hasTX(hash, callback) {