handle merkleblock vs block better.
This commit is contained in:
parent
1c8604477f
commit
b522aa2b06
@ -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() {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user