diff --git a/src/block.js b/src/block.js index 5b4776f..6f4721a 100644 --- a/src/block.js +++ b/src/block.js @@ -167,13 +167,22 @@ class Block { toHex(headersOnly) { return this.toBuffer(headersOnly).toString('hex'); } + checkTxRoots() { + return this.__checkMerkleRoot() && + (this.hasWitnessCommit() ? this.__checkWitnessCommit() : true); + } checkMerkleRoot() { + console.warn('Deprecation Warning: Block method checkMerkleRoot will be ' + + 'deprecated in v5. Please use checkTxRoots instead.'); + return this.checkTxRoots(); + } + __checkMerkleRoot() { if (!this.transactions) throw errorMerkleNoTxes; const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions); return this.merkleRoot.compare(actualMerkleRoot) === 0; } - checkWitnessCommit() { + __checkWitnessCommit() { if (!this.transactions) throw errorMerkleNoTxes; if (!this.hasWitnessCommit()) diff --git a/test/block.js b/test/block.js index 76b043d..e646737 100644 --- a/test/block.js +++ b/test/block.js @@ -125,7 +125,7 @@ describe('Block', function () { }) }) - describe('checkMerkleRoot', function () { + describe('checkTxRoots', function () { fixtures.valid.forEach(function (f) { if (f.hex.length === 160) return @@ -136,14 +136,8 @@ describe('Block', function () { }) it('returns ' + f.valid + ' for ' + f.id, function () { - assert.strictEqual(block.checkMerkleRoot(), true) + assert.strictEqual(block.checkTxRoots(), true) }) - - if (f.witnessCommit) { - it('validates witness commit for ' + f.id, function () { - assert.strictEqual(block.checkWitnessCommit(), true) - }) - } }) }) diff --git a/ts_src/block.ts b/ts_src/block.ts index cb50559..e5ea071 100644 --- a/ts_src/block.ts +++ b/ts_src/block.ts @@ -208,14 +208,25 @@ export class Block { return this.toBuffer(headersOnly).toString('hex') } + checkTxRoots (): boolean { + return this.__checkMerkleRoot() && + (this.hasWitnessCommit() ? this.__checkWitnessCommit() : true) + } + checkMerkleRoot (): boolean { + console.warn('Deprecation Warning: Block method checkMerkleRoot will be ' + + 'deprecated in v5. Please use checkTxRoots instead.') + return this.checkTxRoots() + } + + __checkMerkleRoot (): boolean { if (!this.transactions) throw errorMerkleNoTxes const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions) return this.merkleRoot!.compare(actualMerkleRoot) === 0 } - checkWitnessCommit (): boolean { + __checkWitnessCommit (): boolean { if (!this.transactions) throw errorMerkleNoTxes if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit diff --git a/types/block.d.ts b/types/block.d.ts index ff98de2..3ff2926 100644 --- a/types/block.d.ts +++ b/types/block.d.ts @@ -21,7 +21,9 @@ export declare class Block { getUTCDate(): Date; toBuffer(headersOnly: boolean): Buffer; toHex(headersOnly: boolean): string; + checkTxRoots(): boolean; checkMerkleRoot(): boolean; - checkWitnessCommit(): boolean; + __checkMerkleRoot(): boolean; + __checkWitnessCommit(): boolean; checkProofOfWork(): boolean; }