primitives: more aggressive asserting.
This commit is contained in:
parent
6d1c918793
commit
58da4be8fa
@ -60,23 +60,39 @@ util.inherits(Coin, Output);
|
|||||||
|
|
||||||
Coin.prototype.fromOptions = function fromOptions(options) {
|
Coin.prototype.fromOptions = function fromOptions(options) {
|
||||||
assert(options, 'Coin data is required.');
|
assert(options, 'Coin data is required.');
|
||||||
assert(util.isNumber(options.version));
|
|
||||||
assert(util.isNumber(options.height));
|
|
||||||
assert(util.isNumber(options.value));
|
|
||||||
assert(typeof options.coinbase === 'boolean');
|
|
||||||
assert(typeof options.hash === 'string');
|
|
||||||
assert(util.isNumber(options.index));
|
|
||||||
|
|
||||||
this.version = options.version;
|
if (options.version != null) {
|
||||||
this.height = options.height;
|
assert(util.isUInt32(options.version));
|
||||||
this.value = options.value;
|
this.version = options.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.height != null) {
|
||||||
|
assert(options.height === -1 || util.isUInt32(options.height));
|
||||||
|
this.height = options.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.value != null) {
|
||||||
|
assert(util.isUInt53(options.value));
|
||||||
|
this.value = options.value;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.script)
|
if (options.script)
|
||||||
this.script.fromOptions(options.script);
|
this.script.fromOptions(options.script);
|
||||||
|
|
||||||
this.coinbase = options.coinbase;
|
if (options.coinbase != null) {
|
||||||
this.hash = options.hash;
|
assert(typeof options.coinbase === 'boolean');
|
||||||
this.index = options.index;
|
this.coinbase = options.coinbase;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.hash != null) {
|
||||||
|
assert(typeof options.hash === 'string');
|
||||||
|
this.hash = options.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.index != null) {
|
||||||
|
assert(util.isUInt32(options.index));
|
||||||
|
this.index = options.index;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -56,7 +56,7 @@ Input.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.script.fromOptions(options.script);
|
this.script.fromOptions(options.script);
|
||||||
|
|
||||||
if (options.sequence != null) {
|
if (options.sequence != null) {
|
||||||
assert(util.isNumber(options.sequence));
|
assert(util.isUInt32(options.sequence));
|
||||||
this.sequence = options.sequence;
|
this.sequence = options.sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ Input.prototype.getJSON = function getJSON(network, coin) {
|
|||||||
|
|
||||||
Input.prototype.fromJSON = function fromJSON(json) {
|
Input.prototype.fromJSON = function fromJSON(json) {
|
||||||
assert(json, 'Input data is required.');
|
assert(json, 'Input data is required.');
|
||||||
assert(util.isNumber(json.sequence));
|
assert(util.isUInt32(json.sequence));
|
||||||
this.prevout.fromJSON(json.prevout);
|
this.prevout.fromJSON(json.prevout);
|
||||||
this.script.fromJSON(json.script);
|
this.script.fromJSON(json.script);
|
||||||
this.witness.fromJSON(json.witness);
|
this.witness.fromJSON(json.witness);
|
||||||
@ -451,6 +451,8 @@ Input.fromCoin = function fromCoin(coin) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Input.prototype.fromTX = function fromTX(tx, index) {
|
Input.prototype.fromTX = function fromTX(tx, index) {
|
||||||
|
assert(tx);
|
||||||
|
assert(typeof index === 'number');
|
||||||
assert(index < tx.outputs.length);
|
assert(index < tx.outputs.length);
|
||||||
this.prevout.hash = tx.hash('hex');
|
this.prevout.hash = tx.hash('hex');
|
||||||
this.prevout.index = index;
|
this.prevout.index = index;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ Output.prototype.fromOptions = function fromOptions(options) {
|
|||||||
assert(options, 'Output data is required.');
|
assert(options, 'Output data is required.');
|
||||||
|
|
||||||
if (options.value) {
|
if (options.value) {
|
||||||
assert(util.isNumber(options.value));
|
assert(util.isInt53(options.value));
|
||||||
this.value = options.value;
|
this.value = options.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2250,11 +2250,11 @@ TX.prototype.fromJSON = function fromJSON(json) {
|
|||||||
var i, input, output;
|
var i, input, output;
|
||||||
|
|
||||||
assert(json, 'TX data is required.');
|
assert(json, 'TX data is required.');
|
||||||
assert(util.isNumber(json.version));
|
assert(util.isUInt32(json.version));
|
||||||
assert(util.isNumber(json.flag));
|
assert(util.isUInt8(json.flag));
|
||||||
assert(Array.isArray(json.inputs));
|
assert(Array.isArray(json.inputs));
|
||||||
assert(Array.isArray(json.outputs));
|
assert(Array.isArray(json.outputs));
|
||||||
assert(util.isNumber(json.locktime));
|
assert(util.isUInt32(json.locktime));
|
||||||
|
|
||||||
this.version = json.version;
|
this.version = json.version;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user