add some checks

This commit is contained in:
Manuel Araoz 2015-02-02 16:48:13 -03:00
parent 68015bfb58
commit b9be679e09
3 changed files with 5 additions and 0 deletions

View File

@ -9,6 +9,7 @@ var BufferWriter = require('./encoding/bufferwriter');
var Hash = require('./crypto/hash');
var JSUtil = require('./util/js');
var Transaction = require('./transaction');
var $ = require('./util/preconditions');
/**
* 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) {
var info = {};
$.checkState(!br.finished(), 'No block data received');
info.header = BlockHeader.fromBufferReader(br);
var transactions = br.readVarintNum();
info.transactions = [];

View File

@ -28,6 +28,8 @@ BufferReader.prototype.eof = function() {
return this.pos >= this.buf.length;
};
BufferReader.prototype.finished = BufferReader.prototype.eof;
BufferReader.prototype.read = function(len) {
$.checkArgument(!_.isUndefined(len), 'Must specify a length');
var buf = this.buf.slice(this.pos, this.pos + len);

View File

@ -189,6 +189,7 @@ Transaction.prototype.fromBuffer = function(buffer) {
};
Transaction.prototype.fromBufferReader = function(reader) {
$.checkArgument(!reader.finished(), 'No transaction data received');
var i, sizeTxIns, sizeTxOuts;
this.version = reader.readUInt32LE();