This commit is contained in:
Christopher Jeffrey 2016-04-29 21:04:52 -07:00
parent d89bd13f09
commit 0b8101b756
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 40 additions and 0 deletions

View File

@ -2531,5 +2531,37 @@ Chain.prototype.checkLocks = function checkLocks(tx, flags, entry, callback) {
});
};
/**
* Calculate the difficulty.
* @param {ChainBlock} entry
* @returns {Number} Difficulty.
*/
Chain.prototype.getDifficulty = function getDifficulty(entry) {
var shift, diff;
if (!entry) {
if (!this.tip)
return 1.0;
entry = this.tip;
}
shift = (entry.bits >>> 24) & 0xff;
diff = 0x0000ffff / (entry.bits & 0x00ffffff);
while (shift < 29) {
diff *= 256.0;
shift++;
}
while (shift > 29) {
diff /= 256.0;
shift--;
}
return diff;
};
return Chain;
};

View File

@ -767,3 +767,11 @@ exports.confidence = {
UNKNOWN: 0
};
/**
* The name of our currency.
* @const {String}
* @default
*/
exports.CURRENCY_UNIT = 'BTC';