From 68c16b214a7b2481ee6730bc25c9bccb714673fc Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 22 Dec 2015 02:15:33 -0800 Subject: [PATCH] add `rblock` and `rhash` helpers. --- lib/bcoin/block.js | 4 ++++ lib/bcoin/chain.js | 2 +- lib/bcoin/tx.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index e8ef2354..0436a76a 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -288,6 +288,10 @@ Block.prototype.getNextBlock = function getNextBlock(chain) { return this._nextBlock = next; }; +Block.prototype.__defineGetter__('rblock', function() { + return utils.revHex(this.hash('hex')); +}); + Block.prototype.toJSON = function toJSON() { return { v: '1', diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 36e84d8c..0958ac07 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -607,7 +607,7 @@ Chain.prototype.getHeight = function getHeight(hash) { i = this.index.hashes.indexOf(hash); height = this.index.heights[i]; - if (height === null) + if (height == null) return -1; return height; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index a7347600..7fb43297 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1164,6 +1164,16 @@ TX.prototype.getConfirmations = function getConfirmations(chain) { return top - height + 1; }; +TX.prototype.__defineGetter__('rblock', function() { + return this.block + ? utils.revHex(this.block) + : null; +}); + +TX.prototype.__defineGetter__('rhash', function() { + return utils.revHex(this.hash('hex')); +}); + TX.prototype.toJSON = function toJSON() { // Compact representation return {