From 43b0533a1858a39673ecb15facc8d4ded2747435 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 27 Dec 2015 22:56:53 -0800 Subject: [PATCH] minor improvements and fixes. --- lib/bcoin/block.js | 11 +++++++---- lib/bcoin/input.js | 2 +- lib/bcoin/output.js | 2 +- lib/bcoin/pool.js | 3 ++- lib/bcoin/protocol/framer.js | 5 +++-- lib/bcoin/tx.js | 1 + lib/bcoin/utils.js | 1 + 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 22b24c45..5237661d 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -307,10 +307,13 @@ Block.prototype.getReward = function getReward() { if (this._reward) return this._reward; + base = Block.reward(this.height); + if (this.txs.length === 0 || !this.txs[0].isCoinbase()) { return this._reward = { fee: new bn(0), - reward: Block.reward(this.height) + reward: base, + base: base }; } @@ -319,8 +322,6 @@ Block.prototype.getReward = function getReward() { return total; }, new bn(0)); - base = Block.reward(this.height); - // If height is not accurate, artificially increase // the reward era until base is smaller than the reward. height = 0; @@ -333,7 +334,8 @@ Block.prototype.getReward = function getReward() { return this._reward = { fee: fee, - reward: reward + reward: reward, + base: base }; }; @@ -371,6 +373,7 @@ Block.prototype.inspect = function inspect() { copy.nextBlock = this.nextBlock; copy.reward = utils.btc(this.reward); copy.fee = utils.btc(this.fee); + copy.date = new Date((copy.ts || 0) * 1000).toISOString(); return copy; }; diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index 8bb21713..b43fef99 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -105,7 +105,7 @@ Input.prototype.__defineGetter__('m', function() { }); Input.prototype.__defineGetter__('n', function() { - return this.data.n || this.data.m; + return this.data.n || this.m; }); Input.prototype.__defineGetter__('lock', function() { diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index c54c1196..ad2ee879 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -89,7 +89,7 @@ Output.prototype.__defineGetter__('m', function() { }); Output.prototype.__defineGetter__('n', function() { - return this.data.n || this.data.m; + return this.data.n || this.m; }); Output.prototype.__defineGetter__('lock', function() { diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index de323a55..7681c754 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -569,10 +569,11 @@ Pool.prototype.watch = function watch(id) { Pool.prototype.unwatch = function unwatch(id) { var i; + id = utils.toHex(id); + if (!this.bloom.test(id, 'hex')) return; - id = utils.toHex(id); if (!this.watchMap[id] || --this.watchMap[id] !== 0) return; diff --git a/lib/bcoin/protocol/framer.js b/lib/bcoin/protocol/framer.js index 300060ef..424fcfa4 100644 --- a/lib/bcoin/protocol/framer.js +++ b/lib/bcoin/protocol/framer.js @@ -123,11 +123,12 @@ Framer.prototype.verack = function verack() { Framer.prototype._inv = function _inv(command, items) { var res = []; - var off = utils.writeIntv(res, items.length, 0); - var i, hash; + var off, i, hash; assert(items.length <= 50000); + off = utils.writeIntv(res, items.length, 0); + for (i = 0; i < items.length; i++) { // Type off += writeU32(res, constants.inv[items[i].type], off); diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 991335a1..9efcf0cb 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -914,6 +914,7 @@ TX.prototype.inspect = function inspect() { copy.fee = utils.btc(this.fee); copy.height = this.height; copy.confirmations = this.confirmations; + copy.date = new Date((copy.ts || 0) * 1000).toISOString(); return copy; }; diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index b4b88189..d94010a0 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -595,6 +595,7 @@ utils.toBTC = function toBTC(satoshi, strict) { }; utils.satoshi = +utils.toSatoshi = utils.fromBTC = function fromBTC(btc, strict) { var satoshi, parts, hi, lo;