From 0b8101b756afb78012c7c2f69c5b71e61124be52 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 29 Apr 2016 21:04:52 -0700 Subject: [PATCH] minor. --- lib/bcoin/chain.js | 32 ++++++++++++++++++++++++++++++++ lib/bcoin/protocol/constants.js | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 33a40ae9..b8508308 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -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; }; diff --git a/lib/bcoin/protocol/constants.js b/lib/bcoin/protocol/constants.js index e31fd1ff..0421ac3d 100644 --- a/lib/bcoin/protocol/constants.js +++ b/lib/bcoin/protocol/constants.js @@ -767,3 +767,11 @@ exports.confidence = { UNKNOWN: 0 }; + +/** + * The name of our currency. + * @const {String} + * @default + */ + +exports.CURRENCY_UNIT = 'BTC';