handle merkleblock vs block better.

This commit is contained in:
Christopher Jeffrey 2015-12-22 15:03:17 -08:00
parent 1c8604477f
commit b522aa2b06
2 changed files with 14 additions and 13 deletions

View File

@ -45,23 +45,22 @@ function Block(data, subtype) {
this.tx = [];
this.invalid = false;
if (this.subtype === 'block') {
if (this.subtype === 'merkleblock') {
// Verify partial merkle tree and fill `ts` array
this.invalid = !this._verifyMerkle();
} else if (this.subtype === 'block') {
this.txs = this.txs.map(function(tx) {
tx.network = self.network;
tx.relayedBy = self.relayedBy;
tx = bcoin.tx(tx);
tx.block = self.hash('hex');
tx.ts = tx.ts || self.ts;
// self.tx.push(tx.hash('hex'));
return tx;
});
this.invalid = !this._checkBlock();
}
this._hash = null;
// Verify partial merkle tree and fill `ts` array
this._verifyMerkle();
}
Block.prototype.hash = function hash(enc) {
@ -153,12 +152,12 @@ Block.prototype._verifyMerkle = function verifyMerkle() {
root = visit(1);
if (!root || root !== this.merkleRoot) {
this.invalid = true;
return;
}
if (!root || root !== this.merkleRoot)
return false;
this.tx = tx;
return true;
};
Block.prototype.getMerkleRoot = function getMerkleRoot() {

View File

@ -46,16 +46,18 @@ function TX(data, block) {
this.input(input, null);
}, this);
}
if (data.outputs) {
data.outputs.forEach(function(out) {
this.out(out, null);
}, this);
}
if (!data.ts && block && block.hasTX(this.hash('hex'))) {
// if (block) {
this.ts = block.ts;
this.block = block.hash('hex');
if (block && block.subtype === 'merkleblock') {
if (!data.ts && block && block.hasTX(this.hash('hex'))) {
this.ts = block.ts;
this.block = block.hash('hex');
}
}
// ps = Pending Since