From 3fd3d9bcff0376fed151ab6c77e19612edd4140d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 18 Jun 2016 18:13:25 -0700 Subject: [PATCH] prevout.isNull(). --- lib/bcoin/input.js | 21 ++++++++++++++++----- lib/bcoin/tx.js | 16 ++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index 3cc9fcf9..1953186a 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -12,6 +12,16 @@ var utils = require('./utils'); var assert = utils.assert; var constants = bcoin.protocol.constants; +/** + * Represents a COutPoint. + * @exports Outpoint + * @constructor + * @param {Hash?} hash + * @param {Number?} index + * @property {Hash} hash + * @property {Number} index + */ + function Outpoint(hash, index) { if (!(this instanceof Outpoint)) return new Outpoint(hash, index); @@ -34,6 +44,10 @@ Outpoint.fromOptions = function fromOptions(data) { return new Outpoint().fromOptions(data); }; +Outpoint.prototype.isNull = function isNull() { + return this.hash === constants.NULL_HASH && this.index === 0xffffffff; +}; + Outpoint.prototype.fromRaw = function fromRaw(data) { var p = bcoin.reader(data); this.hash = p.readHash('hex'); @@ -134,9 +148,6 @@ Input.prototype.fromOptions = function fromOptions(options, mutable) { if (options.coin) this.coin = bcoin.coin(options.coin); - assert(typeof this.prevout === 'object'); - assert(typeof this.prevout.hash === 'string'); - assert(typeof this.prevout.index === 'number'); assert(typeof this.sequence === 'number'); return this; @@ -293,12 +304,12 @@ Input.prototype.isFinal = function isFinal() { }; /** - * Test to see if outpoint hash is null. + * Test to see if outpoint is null. * @returns {Boolean} */ Input.prototype.isCoinbase = function isCoinbase() { - return this.prevout.hash === constants.NULL_HASH; + return this.prevout.isNull(); }; /** diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 9ca15cf2..f1ef67df 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -662,12 +662,11 @@ TX.prototype.verifyInput = function verifyInput(index, flags) { flags ); } catch (e) { - if (e.type === 'ScriptError') + if (e.type === 'ScriptError') { bcoin.debug('Script verification error: %s', e.message); - else - bcoin.error(e); - - return false; + return false; + } + throw e; } return true; @@ -719,8 +718,7 @@ TX.prototype.verifyAsync = function verifyAsync(flags, callback) { */ TX.prototype.isCoinbase = function isCoinbase() { - return this.inputs.length === 1 - && this.inputs[0].prevout.hash === constants.NULL_HASH; + return this.inputs.length === 1 && this.inputs[0].prevout.isNull(); }; /** @@ -1246,8 +1244,7 @@ TX.prototype.isSane = function isSane(ret) { } else { for (i = 0; i < this.inputs.length; i++) { input = this.inputs[i]; - if (input.prevout.hash === constants.NULL_HASH - && input.prevout.index === 0xffffffff) { + if (input.prevout.isNull()) { ret.reason = 'bad-txns-prevout-null'; ret.score = 10; return false; @@ -2268,5 +2265,4 @@ TX.isTX = function isTX(obj) { * Expose */ - module.exports = TX;