add some checks
This commit is contained in:
parent
68015bfb58
commit
b9be679e09
@ -9,6 +9,7 @@ var BufferWriter = require('./encoding/bufferwriter');
|
|||||||
var Hash = require('./crypto/hash');
|
var Hash = require('./crypto/hash');
|
||||||
var JSUtil = require('./util/js');
|
var JSUtil = require('./util/js');
|
||||||
var Transaction = require('./transaction');
|
var Transaction = require('./transaction');
|
||||||
|
var $ = require('./util/preconditions');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a Block from a Buffer, JSON object, or Object with
|
* Instantiate a Block from a Buffer, JSON object, or Object with
|
||||||
@ -96,6 +97,7 @@ Block.fromJSON = function fromJSON(json) {
|
|||||||
*/
|
*/
|
||||||
Block._fromBufferReader = function _fromBufferReader(br) {
|
Block._fromBufferReader = function _fromBufferReader(br) {
|
||||||
var info = {};
|
var info = {};
|
||||||
|
$.checkState(!br.finished(), 'No block data received');
|
||||||
info.header = BlockHeader.fromBufferReader(br);
|
info.header = BlockHeader.fromBufferReader(br);
|
||||||
var transactions = br.readVarintNum();
|
var transactions = br.readVarintNum();
|
||||||
info.transactions = [];
|
info.transactions = [];
|
||||||
|
|||||||
@ -28,6 +28,8 @@ BufferReader.prototype.eof = function() {
|
|||||||
return this.pos >= this.buf.length;
|
return this.pos >= this.buf.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BufferReader.prototype.finished = BufferReader.prototype.eof;
|
||||||
|
|
||||||
BufferReader.prototype.read = function(len) {
|
BufferReader.prototype.read = function(len) {
|
||||||
$.checkArgument(!_.isUndefined(len), 'Must specify a length');
|
$.checkArgument(!_.isUndefined(len), 'Must specify a length');
|
||||||
var buf = this.buf.slice(this.pos, this.pos + len);
|
var buf = this.buf.slice(this.pos, this.pos + len);
|
||||||
|
|||||||
@ -189,6 +189,7 @@ Transaction.prototype.fromBuffer = function(buffer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.fromBufferReader = function(reader) {
|
Transaction.prototype.fromBufferReader = function(reader) {
|
||||||
|
$.checkArgument(!reader.finished(), 'No transaction data received');
|
||||||
var i, sizeTxIns, sizeTxOuts;
|
var i, sizeTxIns, sizeTxOuts;
|
||||||
|
|
||||||
this.version = reader.readUInt32LE();
|
this.version = reader.readUInt32LE();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user