From 5cbbf5a186404dc3879b86d580bbd3e3c4a5ed01 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 26 May 2020 11:02:12 +0700 Subject: [PATCH] Crash fix. --- backend/src/api/blocks.ts | 2 +- backend/src/api/common.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 9372f8039..061269146 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -75,7 +75,7 @@ class Blocks { block.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0); transactions.sort((a, b) => b.feePerVsize - a.feePerVsize); block.medianFee = transactions.length > 1 ? Common.median(transactions.map((tx) => tx.feePerVsize)) : 0; - block.feeRange = transactions.length > 1 ? Common.getFeesInRange(transactions, 8) : [0, 0]; + block.feeRange = transactions.length > 1 ? Common.getFeesInRange(transactions, 8, 1) : [0, 0]; block.coinbaseTx = this.stripCoinbaseTransaction(transactions[0]); this.blocks.push(block); diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 2d63804f7..ca6e2c1cc 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -12,7 +12,7 @@ export class Common { return medianNr; } - static getFeesInRange(transactions: TransactionExtended[], rangeLength: number) { + static getFeesInRange(transactions: TransactionExtended[], rangeLength: number, lastindex = 0) { const arr = [transactions[transactions.length - 1].feePerVsize]; const chunk = 1 / (rangeLength - 1); let itemsToAdd = rangeLength - 2; @@ -22,7 +22,7 @@ export class Common { itemsToAdd--; } - arr.push(transactions[1].feePerVsize); + arr.push(transactions[lastindex].feePerVsize); return arr; } }