Browse Source
Move to checkTxRoots and warn checkMerkleRoot deprecation
fixTypes
junderw
6 years ago
No known key found for this signature in database
GPG Key ID: B256185D3A971908
4 changed files with
27 additions and
11 deletions
-
src/block.js
-
test/block.js
-
ts_src/block.ts
-
types/block.d.ts
|
|
@ -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()) |
|
|
|
|
|
@ -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) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|