types. do not mark compactblocks as valid.

This commit is contained in:
Christopher Jeffrey 2016-04-17 02:53:02 -07:00
parent 45ac59330e
commit 1c7d3082dc
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 21 additions and 28 deletions

View File

@ -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;

View File

@ -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';
};
/**

View File

@ -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;
};