diff --git a/Connection.js b/Connection.js index 61786f5..f7078ee 100644 --- a/Connection.js +++ b/Connection.js @@ -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); diff --git a/const.js b/const.js new file mode 100644 index 0000000..cd6a77e --- /dev/null +++ b/const.js @@ -0,0 +1,7 @@ + +exports.MSG = { + TX: 1, + BLOCK: 2, + FILTERED_BLOCK: 3, +}; +