Connection, const: add bits necessary for getheaders/headers

This commit is contained in:
Jeff Garzik 2013-08-02 15:02:45 -04:00
parent 420773ac39
commit 5b69342356
2 changed files with 27 additions and 2 deletions

View File

@ -187,7 +187,7 @@ function spec(b) {
this.sendMessage('version', put.buffer());
};
Connection.prototype.sendGetBlocks = function (starts, stop) {
Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) {
var put = new Put();
put.word32le(this.sendVer);
@ -207,7 +207,14 @@ function spec(b) {
put.put(stopBuffer);
this.sendMessage('getblocks', put.buffer());
var command = 'getblocks';
if (wantHeaders)
command = 'getheaders';
this.sendMessage(command, put.buffer());
};
Connection.prototype.sendGetHeaders = function(starts, stop) {
this.sendGetBlocks(starts, stop, true);
};
Connection.prototype.sendGetData = function (invs) {
@ -432,6 +439,17 @@ function spec(b) {
}
break;
case 'headers':
data.count = parser.varInt();
data.headers = [];
for (i = 0; i < data.count; i++) {
var header = new Block();
header.parse(parser);
data.headers.push(header);
}
break;
case 'block':
var block = new Block();
block.parse(parser);

7
const.js Normal file
View File

@ -0,0 +1,7 @@
exports.MSG = {
TX: 1,
BLOCK: 2,
FILTERED_BLOCK: 3,
};