diff --git a/lib/bcoin/compactblock.js b/lib/bcoin/compactblock.js index 2ef4e53f..73094a44 100644 --- a/lib/bcoin/compactblock.js +++ b/lib/bcoin/compactblock.js @@ -54,7 +54,6 @@ function CompactBlock(data) { bcoin.abstractblock.call(this, data); - this.type = 'compactblock'; this.coinbaseHeight = -1; if (this.version >= 2) { @@ -94,13 +93,10 @@ CompactBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() { */ CompactBlock.prototype.toBlock = function toBlock() { - var block = bcoin.protocol.parser.parseBlock(this._raw); + var data = bcoin.protocol.parser.parseBlock(this._raw); delete this._raw; - assert(!block._raw); - block = new bcoin.block(block); - if (this.valid != null) - block.valid = this.valid; - return block; + assert(!data._raw); + return new bcoin.block(data); }; /** @@ -109,10 +105,8 @@ CompactBlock.prototype.toBlock = function toBlock() { * @returns {Boolean} */ -CompactBlock.isCompactBlock = function isCompactBlock(block) { - return block - && block.type === 'compactblock' - && typeof block.toBlock === 'function'; +CompactBlock.isCompactBlock = function isCompactBlock(obj) { + return obj && typeof obj.toBlock === 'function'; }; return CompactBlock; diff --git a/lib/bcoin/headers.js b/lib/bcoin/headers.js index 7e736aca..8dafc0ef 100644 --- a/lib/bcoin/headers.js +++ b/lib/bcoin/headers.js @@ -34,8 +34,6 @@ function Headers(data) { return new Headers(data); bcoin.abstractblock.call(this, data); - - this.type = 'headers'; } utils.inherits(Headers, bcoin.abstractblock); @@ -151,7 +149,10 @@ Headers.fromRaw = function fromRaw(data, enc) { */ Headers.isHeaders = function isHeaders(obj) { - return obj && obj.type === 'headers' && typeof obj.render === 'function'; + return obj + && !obj.txs + && typeof obj.abbr === 'function' + && typeof obj.toBlock !== 'function'; }; /** diff --git a/lib/bcoin/merkleblock.js b/lib/bcoin/merkleblock.js index e0e1c615..4cdd7c2c 100644 --- a/lib/bcoin/merkleblock.js +++ b/lib/bcoin/merkleblock.js @@ -41,8 +41,6 @@ function MerkleBlock(data) { bcoin.abstractblock.call(this, data); - this.type = 'merkleblock'; - this.hashes = (data.hashes || []).map(function(hash) { return utils.toBuffer(hash, 'hex'); }); @@ -284,18 +282,6 @@ MerkleBlock.fromRaw = function fromRaw(data, enc) { return new MerkleBlock(MerkleBlock._fromRaw(data, enc)); }; -/** - * Test an object to see if it is a MerkleBlock object. - * @param {Object} obj - * @returns {Boolean} - */ - -MerkleBlock.isMerkleBlock = function isMerkleBlock(obj) { - return obj - && Array.isArray(obj.flags) - && typeof obj._verifyPartial === 'function'; -}; - /** * Create a merkleblock from a {@link Block} object, passing * it through a filter first. This will build the partial @@ -394,5 +380,17 @@ MerkleBlock.fromBlock = function fromBlock(block, bloom) { return block; }; +/** + * Test an object to see if it is a MerkleBlock object. + * @param {Object} obj + * @returns {Boolean} + */ + +MerkleBlock.isMerkleBlock = function isMerkleBlock(obj) { + return obj + && Array.isArray(obj.flags) + && typeof obj._verifyPartial === 'function'; +}; + return MerkleBlock; };