fix getChainwork.

This commit is contained in:
Christopher Jeffrey 2016-01-23 22:00:19 -08:00
parent 7526beace0
commit 0d7929136a

View File

@ -1163,18 +1163,15 @@ ChainBlock.prototype.__defineGetter__('next', function() {
return this.chain.db.get(this.height + 1); return this.chain.db.get(this.height + 1);
}); });
ChainBlock.prototype.__defineGetter__('proof', function() { ChainBlock.prototype.getProof = function getProof() {
var target = utils.fromCompact(this.bits); var target = utils.fromCompact(this.bits);
if (target.isNeg() || target.cmpn(0) === 0) if (target.isNeg() || target.cmpn(0) === 0)
return new bn(0); return new bn(0);
return new bn(1).ushln(256).div(target.addn(1)); return new bn(1).ushln(256).div(target.addn(1));
}); };
ChainBlock.prototype.getChainwork = function() { ChainBlock.prototype.getChainwork = function() {
if (!this.prev) return (this.prev ? this.prev.chainwork : new bn(0)).add(this.getProof());
return new bn(0);
return (this.prev ? this.prev.chainwork : new bn(0)).add(this.proof);
}; };
ChainBlock.prototype.getMedianTime = function() { ChainBlock.prototype.getMedianTime = function() {