This commit is contained in:
Christopher Jeffrey 2016-06-18 17:42:49 -07:00
parent 75aad4e771
commit 821f1175cc
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 26 additions and 66 deletions

View File

@ -755,8 +755,10 @@ Chain.prototype._checkDuplicates = function _checkDuplicates(block, prev, callba
if (this.isGenesis(block)) if (this.isGenesis(block))
return callback(); return callback();
if (this.network.block.bip34height === -1 || height <= this.network.block.bip34height) if (this.network.block.bip34height === -1
|| height <= this.network.block.bip34height) {
return this._findDuplicates(block, prev, callback); return this._findDuplicates(block, prev, callback);
}
this.db.get(this.network.block.bip34height, function(err, entry) { this.db.get(this.network.block.bip34height, function(err, entry) {
if (err) if (err)

View File

@ -59,7 +59,7 @@ Coin.prototype.fromOptions = function fromOptions(options) {
this.hash = options.hash; this.hash = options.hash;
this.index = options.index; this.index = options.index;
assert(typeof this.version === 'number'); assert(utils.isNumber(this.version));
assert(utils.isNumber(this.height)); assert(utils.isNumber(this.height));
assert(typeof this.value === 'number'); assert(typeof this.value === 'number');
assert(this.script instanceof bcoin.script); assert(this.script instanceof bcoin.script);

View File

@ -24,37 +24,31 @@ var ScriptError = bcoin.errors.ScriptError;
* Refers to the witness field of segregated witness transactions. * Refers to the witness field of segregated witness transactions.
* @exports Witness * @exports Witness
* @constructor * @constructor
* @param {Buffer[]|Buffer|NakedWitness} items - Array of * @param {Buffer[]|NakedWitness} items - Array of
* stack items or raw witness buffer. * stack items.
* @property {Buffer[]} items * @property {Buffer[]} items
* @property {Script?} redeem * @property {Script?} redeem
* @property {Number} length * @property {Number} length
*/ */
function Witness(items) { function Witness(options) {
if (items instanceof Witness) if (options instanceof Witness)
return items; return options;
if (!(this instanceof Witness)) if (!(this instanceof Witness))
return new Witness(items); return new Witness(options);
this.items = []; this.items = [];
this.redeem = null; this.redeem = null;
if (items) if (options)
this.fromOptions(items); this.fromOptions(options);
} }
Witness.prototype.fromOptions = function fromOptions(items) { Witness.prototype.fromOptions = function fromOptions(options) {
if (items.items) this.items = options.items || options;
items = items.items;
this.items = items;
this.redeem = null; this.redeem = null;
assert(Array.isArray(this.items)); assert(Array.isArray(this.items));
return this; return this;
}; };
@ -1034,19 +1028,19 @@ Stack.isStack = function isStack(obj) {
* @property {Number} length * @property {Number} length
*/ */
function Script(raw) { function Script(options) {
if (raw instanceof Script) if (options instanceof Script)
return raw; return options;
if (!(this instanceof Script)) if (!(this instanceof Script))
return new Script(raw); return new Script(options);
this.raw = STACK_FALSE; this.raw = STACK_FALSE;
this.code = []; this.code = [];
this.redeem = null; this.redeem = null;
if (raw) if (options)
this.fromOptions(raw); this.fromOptions(options);
} }
Script.prototype.fromOptions = function fromOptions(options) { Script.prototype.fromOptions = function fromOptions(options) {
@ -1066,7 +1060,6 @@ Script.prototype.fromOptions = function fromOptions(options) {
this.raw = raw; this.raw = raw;
this.code = code; this.code = code;
this.redeem = null;
if (!this.raw) { if (!this.raw) {
assert(this.code); assert(this.code);
@ -1082,10 +1075,10 @@ Script.prototype.fromOptions = function fromOptions(options) {
return this; return this;
}; };
Script.fromOptions = function fromOptions(raw) { Script.fromOptions = function fromOptions(options) {
if (raw instanceof Script) if (options instanceof Script)
return raw; return options;
return new Script().fromOptions(raw); return new Script().fromOptions(options);
}; };
/** /**

View File

@ -644,47 +644,12 @@ utils.merge = function merge(target) {
/** /**
* Assertion. * Assertion.
* @function
* @param {Boolean} value - Expression. * @param {Boolean} value - Expression.
* @param {String?} message - Optional error message. * @param {String?} message - Optional error message.
*/ */
utils.assert = function _assert(value, message) { utils.assert = assert;
if (!value) {
throw new assert.AssertionError({
message: message,
actual: value,
expected: true,
operator: '==',
stackStartFunction: _assert
});
}
};
utils.merge(utils.assert, assert);
utils.assert.fatal = function fatal(value, message) {
var err;
if (!value) {
if (!message)
message = 'Assertion failed (fatal exception)';
err = new assert.AssertionError({
message: message,
actual: value,
expected: true,
operator: '==',
stackStartFunction: fatal
});
if (process.exit) {
console.error(err.stack + '');
process.exit(1);
} else {
throw err;
}
}
};
/** /**
* Safely convert satoshis to a BTC string. * Safely convert satoshis to a BTC string.