added difficulty chart in history

This commit is contained in:
cubedro 2015-04-28 04:45:23 +03:00
parent f2a7f31b64
commit d1d8603fd9
1 changed files with 16 additions and 1 deletions

View File

@ -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();