block: remove commitment hash cache.

This commit is contained in:
Christopher Jeffrey 2017-02-14 01:18:17 -08:00
parent f71f2d954b
commit 426ab85f15
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -38,7 +38,6 @@ function Block(options) {
this.txs = [];
this._cbHeight = null;
this._commitmentHash = null;
this._raw = null;
this._size = -1;
@ -400,32 +399,23 @@ Block.prototype.getWitnessNonce = function getWitnessNonce() {
*/
Block.prototype.getCommitmentHash = function getCommitmentHash(enc) {
var hash = this._commitmentHash;
var i, coinbase, output;
var coinbase = this.txs[0];
var i, hash, output;
if (!hash) {
coinbase = this.txs[0];
if (!coinbase)
return null;
if (!coinbase)
return null;
for (i = coinbase.outputs.length - 1; i >= 0; i--) {
output = coinbase.outputs[i];
if (output.script.isCommitment()) {
hash = output.script.getCommitmentHash();
if (!this.mutable)
this._commitmentHash = hash;
break;
}
for (i = coinbase.outputs.length - 1; i >= 0; i--) {
output = coinbase.outputs[i];
if (output.script.isCommitment()) {
hash = output.script.getCommitmentHash();
break;
}
if (!hash)
return null;
}
if (!hash)
return null;
return enc === 'hex'
? hash.toString('hex')
: hash;