Browse Source

add some checks

patch-2
Manuel Araoz 10 years ago
parent
commit
b9be679e09
  1. 2
      lib/block.js
  2. 2
      lib/encoding/bufferreader.js
  3. 1
      lib/transaction/transaction.js

2
lib/block.js

@ -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 = [];

2
lib/encoding/bufferreader.js

@ -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);

1
lib/transaction/transaction.js

@ -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…
Cancel
Save