add _checkFinished
This commit is contained in:
parent
7119fad398
commit
13361ea210
@ -159,7 +159,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
|||||||
});
|
});
|
||||||
var from = [blockHash[network.name]];
|
var from = [blockHash[network.name]];
|
||||||
var stop = stopBlock[network.name];
|
var stop = stopBlock[network.name];
|
||||||
it('gets headers', function(cb) {
|
it.only('gets headers', function(cb) {
|
||||||
connect(function(peer) {
|
connect(function(peer) {
|
||||||
peer.once('headers', function(message) {
|
peer.once('headers', function(message) {
|
||||||
(message instanceof Messages.Headers).should.equal(true);
|
(message instanceof Messages.Headers).should.equal(true);
|
||||||
|
|||||||
@ -169,6 +169,13 @@ Message.prototype.serialize = function(network) {
|
|||||||
return message.buffer();
|
return message.buffer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if parser has no more extra data
|
||||||
|
*/
|
||||||
|
Message.prototype._checkFinished = function(parser) {
|
||||||
|
$.checkState(parser.finished(), 'data still available after parsing ' + this.constructor.name);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.Message = Message;
|
module.exports.Message = Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,7 +261,7 @@ Version.prototype.fromBuffer = function(payload) {
|
|||||||
*/
|
*/
|
||||||
this.relay = !!parser.readUInt8();
|
this.relay = !!parser.readUInt8();
|
||||||
|
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -336,7 +343,7 @@ Inventory.prototype.fromBuffer = function(payload) {
|
|||||||
this.inventory.push(Inventory.forItem(type, hash));
|
this.inventory.push(Inventory.forItem(type, hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -420,7 +427,8 @@ util.inherits(Ping, Message);
|
|||||||
Ping.prototype.fromBuffer = function(payload) {
|
Ping.prototype.fromBuffer = function(payload) {
|
||||||
var parser = new BufferReader(payload);
|
var parser = new BufferReader(payload);
|
||||||
this.nonce = parser.read(8);
|
this.nonce = parser.read(8);
|
||||||
$.checkState(parser.finished());
|
|
||||||
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -532,7 +540,7 @@ Addresses.prototype.fromBuffer = function(payload) {
|
|||||||
this.addresses.push(addr);
|
this.addresses.push(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -607,7 +615,7 @@ Alert.prototype.fromBuffer = function(payload) {
|
|||||||
var parser = new BufferReader(payload);
|
var parser = new BufferReader(payload);
|
||||||
this.payload = parser.readVarLengthBuffer();
|
this.payload = parser.readVarLengthBuffer();
|
||||||
this.signature = parser.readVarLengthBuffer();
|
this.signature = parser.readVarLengthBuffer();
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -651,7 +659,7 @@ Headers.prototype.fromBuffer = function(payload) {
|
|||||||
var header = BlockHeaderModel.fromBufferReader(parser);
|
var header = BlockHeaderModel.fromBufferReader(parser);
|
||||||
this.headers.push(header);
|
this.headers.push(header);
|
||||||
}
|
}
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -777,7 +785,7 @@ GetBlocks.prototype.fromBuffer = function(payload) {
|
|||||||
this.starts.push(parser.read(32));
|
this.starts.push(parser.read(32));
|
||||||
}
|
}
|
||||||
this.stop = parser.read(32);
|
this.stop = parser.read(32);
|
||||||
$.checkState(parser.finished());
|
this._checkFinished(parser);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user