types. do not mark compactblocks as valid.
This commit is contained in:
parent
45ac59330e
commit
1c7d3082dc
@ -54,7 +54,6 @@ function CompactBlock(data) {
|
|||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'compactblock';
|
|
||||||
this.coinbaseHeight = -1;
|
this.coinbaseHeight = -1;
|
||||||
|
|
||||||
if (this.version >= 2) {
|
if (this.version >= 2) {
|
||||||
@ -94,13 +93,10 @@ CompactBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CompactBlock.prototype.toBlock = function toBlock() {
|
CompactBlock.prototype.toBlock = function toBlock() {
|
||||||
var block = bcoin.protocol.parser.parseBlock(this._raw);
|
var data = bcoin.protocol.parser.parseBlock(this._raw);
|
||||||
delete this._raw;
|
delete this._raw;
|
||||||
assert(!block._raw);
|
assert(!data._raw);
|
||||||
block = new bcoin.block(block);
|
return new bcoin.block(data);
|
||||||
if (this.valid != null)
|
|
||||||
block.valid = this.valid;
|
|
||||||
return block;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,10 +105,8 @@ CompactBlock.prototype.toBlock = function toBlock() {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CompactBlock.isCompactBlock = function isCompactBlock(block) {
|
CompactBlock.isCompactBlock = function isCompactBlock(obj) {
|
||||||
return block
|
return obj && typeof obj.toBlock === 'function';
|
||||||
&& block.type === 'compactblock'
|
|
||||||
&& typeof block.toBlock === 'function';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return CompactBlock;
|
return CompactBlock;
|
||||||
|
|||||||
@ -34,8 +34,6 @@ function Headers(data) {
|
|||||||
return new Headers(data);
|
return new Headers(data);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'headers';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Headers, bcoin.abstractblock);
|
utils.inherits(Headers, bcoin.abstractblock);
|
||||||
@ -151,7 +149,10 @@ Headers.fromRaw = function fromRaw(data, enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Headers.isHeaders = function isHeaders(obj) {
|
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';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -41,8 +41,6 @@ function MerkleBlock(data) {
|
|||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'merkleblock';
|
|
||||||
|
|
||||||
this.hashes = (data.hashes || []).map(function(hash) {
|
this.hashes = (data.hashes || []).map(function(hash) {
|
||||||
return utils.toBuffer(hash, 'hex');
|
return utils.toBuffer(hash, 'hex');
|
||||||
});
|
});
|
||||||
@ -284,18 +282,6 @@ MerkleBlock.fromRaw = function fromRaw(data, enc) {
|
|||||||
return new MerkleBlock(MerkleBlock._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
|
* Create a merkleblock from a {@link Block} object, passing
|
||||||
* it through a filter first. This will build the partial
|
* it through a filter first. This will build the partial
|
||||||
@ -394,5 +380,17 @@ MerkleBlock.fromBlock = function fromBlock(block, bloom) {
|
|||||||
return block;
|
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;
|
return MerkleBlock;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user