From d1d8603fd908d08c75f30e6e5bf7a8e773d747b4 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 04:45:23 +0300 Subject: [PATCH] added difficulty chart in history --- models/history.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/models/history.js b/models/history.js index 213959a..1c2375a 100644 --- a/models/history.js +++ b/models/history.js @@ -33,7 +33,7 @@ var History = function History(data) History.prototype.add = function(block, id) { - if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined') + if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined' && typeof block.difficulty !== 'undefined') { var historyBlock = this.search(block.number); @@ -201,6 +201,21 @@ History.prototype.getTransactionsCount = function(id) return txCount; } +History.prototype.getDifficulty = function(id) +{ + var difficultyHistory = _(this._items) + .sortByOrder('height', false) + .slice(0, MAX_BINS - 1) + .reverse() + .map(function(item) + { + return item.block.difficulty; + }) + .value(); + + return difficultyHistory; +} + History.prototype.history = function() { return _.chain(this._items).sortBy('number').reverse().value();