prevout.isNull().

This commit is contained in:
Christopher Jeffrey 2016-06-18 18:13:25 -07:00
parent 821f1175cc
commit 3fd3d9bcff
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 22 additions and 15 deletions

View File

@ -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();
};
/**

View File

@ -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;