chain: add getProofTime.
This commit is contained in:
parent
b60e0e20a4
commit
de0a60340b
@ -1825,6 +1825,34 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
||||
return root;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the time difference (in seconds)
|
||||
* between two blocks by examining chainworks.
|
||||
* @param {ChainEntry} to
|
||||
* @param {ChainEntry} from
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Chain.prototype.getProofTime = function getProofTime(to, from) {
|
||||
var sign, work;
|
||||
|
||||
if (to.chainwork.cmp(from.chainwork) > 0) {
|
||||
work = to.chainwork.sub(from.chainwork);
|
||||
sign = 1;
|
||||
} else {
|
||||
work = from.chainwork.sub(to.chainwork);
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
work = work.imuln(this.network.pow.targetSpacing);
|
||||
work = work.idiv(this.tip.getProof());
|
||||
|
||||
if (work.bitLength() > 53)
|
||||
return sign * util.MAX_SAFE_INTEGER;
|
||||
|
||||
return sign * work.toNumber();
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the next target based on the chain tip.
|
||||
* @returns {Promise} - returns Number
|
||||
|
||||
Loading…
Reference in New Issue
Block a user