From 3a506a70371713416caeb60407710858e1f932b2 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Mon, 18 Feb 2019 21:41:10 +0100 Subject: [PATCH] Update backend lodash #2 --- lib/history.js | 44 ++++++++++++++++++++++---------------------- package.json | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/history.js b/lib/history.js index 82cde66..decfa7d 100644 --- a/lib/history.js +++ b/lib/history.js @@ -228,7 +228,7 @@ History.prototype._save = function(block) { this._items.unshift(block); - this._items = _.sortByOrder( this._items, 'height', false ); + this._items = _.sortBy( this._items, 'height', false ); if(this._items.length > MAX_HISTORY) { @@ -314,7 +314,7 @@ History.prototype.getNodePropagation = function(id) _.fill(propagation, -1); var sorted = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) .slice( 0, MAX_PEER_PROPAGATION ) .forEach(function (item, key) { @@ -392,7 +392,7 @@ History.prototype.getBlockPropagation = function() History.prototype.getUncleCount = function() { var uncles = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -420,7 +420,7 @@ History.prototype.getUncleCount = function() History.prototype.getBlockTimes = function() { var blockTimes = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -439,7 +439,7 @@ History.prototype.getBlockTimes = function() History.prototype.getAvgBlocktime = function() { var blockTimes = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -458,7 +458,7 @@ History.prototype.getAvgBlocktime = function() History.prototype.getGasLimit = function() { var gasLimitHistory = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -477,7 +477,7 @@ History.prototype.getGasLimit = function() History.prototype.getDifficulty = function() { var difficultyHistory = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) .filter(function (item) { return item.block.trusted; @@ -496,7 +496,7 @@ History.prototype.getDifficulty = function() History.prototype.getTransactionsCount = function() { var txCount = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) .filter(function (item) { return item.block.trusted; @@ -515,7 +515,7 @@ History.prototype.getTransactionsCount = function() History.prototype.getGasSpending = function() { var gasSpending = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) .filter(function (item) { return item.block.trusted; @@ -537,7 +537,7 @@ History.prototype.getAvgHashrate = function() return 0; var blocktimeHistory = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -557,7 +557,7 @@ History.prototype.getAvgHashrate = function() History.prototype.getMinersCount = function() { var miners = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -577,7 +577,7 @@ History.prototype.getMinersCount = function() }); return _(minerCount) - .sortByOrder( 'blocks', false ) + .sortBy( 'blocks', false ) .slice(0, 2) .value(); } @@ -592,7 +592,7 @@ History.prototype.getCharts = function() if(this._callback !== null) { var chartHistory = _( this._items ) - .sortByOrder( 'height', false ) + .sortBy( 'height', false ) // .filter(function (item) // { // return item.block.trusted; @@ -615,15 +615,15 @@ History.prototype.getCharts = function() .value(); this._callback(null, { - height : _.pluck( chartHistory, 'height' ), - blocktime : _.pluck( chartHistory, 'blocktime' ), - // avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length), + height : _.map( chartHistory, 'height' ), + blocktime : _.map( chartHistory, 'blocktime' ), + // avgBlocktime : _.sum(_.map( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length), avgBlocktime : this.getAvgBlocktime(), - difficulty : _.pluck( chartHistory, 'difficulty' ), - uncles : _.pluck( chartHistory, 'uncles' ), - transactions : _.pluck( chartHistory, 'transactions' ), - gasSpending : _.pluck( chartHistory, 'gasSpending' ), - gasLimit : _.pluck( chartHistory, 'gasLimit' ), + difficulty : _.map( chartHistory, 'difficulty' ), + uncles : _.map( chartHistory, 'uncles' ), + transactions : _.map( chartHistory, 'transactions' ), + gasSpending : _.map( chartHistory, 'gasSpending' ), + gasLimit : _.map( chartHistory, 'gasLimit' ), miners : this.getMinersCount(), propagation : this.getBlockPropagation(), uncleCount : this.getUncleCount(), @@ -643,7 +643,7 @@ History.prototype.getHistoryRequestRange = function() if( this._items.length < 2 ) return false; - var blocks = _.pluck( this._items, 'height' ); + var blocks = _.map( this._items, 'height' ); var best = _.max( blocks ); var range = _.range( _.max([ 0, best - MAX_HISTORY ]), best + 1); diff --git a/package.json b/package.json index 64fc3ee..7d2a64d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "grunt-contrib-jade": "^1.0.0", "grunt-contrib-uglify": "^4.0.0", "jade": "^1.11.0", - "lodash": "3.10.1", + "lodash": "4.17.11", "primus": "^7.3.1", "primus-emit": "^1.0.0", "primus-spark-latency": "^0.1.1",