Move to checkTxRoots and warn checkMerkleRoot deprecation

This commit is contained in:
junderw 2019-01-17 17:01:15 +09:00
parent 581ab5f136
commit e52abecee2
No known key found for this signature in database
GPG key ID: B256185D3A971908
4 changed files with 27 additions and 11 deletions
ts_src

View file

@ -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