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 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 = [];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue