From e04931026cf1b1116fa7a63e38593aebe23be03c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 18 May 2014 10:03:44 -0500 Subject: [PATCH] block: add block subtype - block or merkleblock. Signed-off-by: Fedor Indutny --- lib/bcoin/block.js | 5 +++-- lib/bcoin/chain.js | 2 +- lib/bcoin/peer.js | 2 +- test/block-test.js | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 081e934d..8ba5b785 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -1,11 +1,12 @@ var bcoin = require('../bcoin'); var utils = bcoin.utils; -function Block(data) { +function Block(data, subtype) { if (!(this instanceof Block)) - return new Block(data); + return new Block(data, subtype); this.type = 'block'; + this.subtype = subtype; this.version = data.version; this.prevBlock = utils.toHex(data.prevBlock); this.merkleRoot = utils.toHex(data.merkleRoot); diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 4906f5cd..bfe0a24f 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -449,7 +449,7 @@ Chain.prototype.fromJSON = function fromJSON(json) { this.index.bloom = new bcoin.bloom(28 * 1024 * 1024, 16, 0xdeadbee0); if (this.index.hashes.length === 0) - this.add(new bcoin.block(constants.genesis)); + this.add(new bcoin.block(constants.genesis, 'block')); for (var i = 0; i < this.index.hashes.length; i++) { this.index.bloom.add(this.index.hashes[i], 'hex'); diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 179a3338..55af3f0e 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -278,7 +278,7 @@ Peer.prototype._onPacket = function onPacket(packet) { return this._handlePong(payload); if (cmd === 'merkleblock' || cmd === 'block') { - payload = bcoin.block(payload); + payload = bcoin.block(payload, cmd); this.lastBlock = payload; } else if (cmd === 'tx') { payload = bcoin.tx(payload, this.lastBlock); diff --git a/test/block-test.js b/test/block-test.js index fb55b5ff..391c0783 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -25,7 +25,7 @@ describe('Block', function() { '1f5e46b9da3a8b1241f4a1501741d3453bafddf6135b600b926e3f4056c6d564', '33825657ba32afe269819f01993bd77baba86379043168c94845d32370e53562' ], flags: [ 245, 90, 0 ] - }); + }, 'merkleblock'); assert(block.verify()); assert.equal(block.tx.length, 2);