From 9ee84ccc2cf96f7ec0e987d6613f3e3533dc62c8 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Sat, 21 Apr 2018 00:09:39 -0400 Subject: [PATCH] use coin-specific block-reward schedule (litecoin was wrong) --- app/coins/btc.js | 14 ++++++++++++++ app/coins/ltc.js | 14 ++++++++++++++ app/utils.js | 15 --------------- views/includes/block-content.pug | 4 ++-- views/transaction.pug | 4 ++-- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/app/coins/btc.js b/app/coins/btc.js index a14cf1d..ac059ee 100644 --- a/app/coins/btc.js +++ b/app/coins/btc.js @@ -1,3 +1,6 @@ +var Decimal = require("decimal.js"); +Decimal8 = Decimal.clone({ precision:8, rounding:8 }); + module.exports = { name:"Bitcoin", logoUrl:"/img/logo/btc.svg", @@ -161,5 +164,16 @@ module.exports = { return -1; } + }, + blockRewardFunction:function(blockHeight) { + var eras = [ new Decimal8(50) ]; + for (var i = 1; i < 34; i++) { + var previous = eras[i - 1]; + eras.push(new Decimal8(previous).dividedBy(2)); + } + + var index = Math.floor(blockHeight / 210000); + + return eras[index]; } }; \ No newline at end of file diff --git a/app/coins/ltc.js b/app/coins/ltc.js index dcf779a..5513a18 100644 --- a/app/coins/ltc.js +++ b/app/coins/ltc.js @@ -1,3 +1,6 @@ +var Decimal = require("decimal.js"); +Decimal8 = Decimal.clone({ precision:8, rounding:8 }); + module.exports = { name:"Litecoin", logoUrl:"/img/logo/ltc.svg", @@ -82,5 +85,16 @@ module.exports = { return -1; } + }, + blockRewardFunction:function(blockHeight) { + var eras = [ new Decimal8(50) ]; + for (var i = 1; i < 34; i++) { + var previous = eras[i - 1]; + eras.push(new Decimal8(previous).dividedBy(2)); + } + + var index = Math.floor(blockHeight / 840000); + + return eras[index]; } }; \ No newline at end of file diff --git a/app/utils.js b/app/utils.js index 5716bde..16b7676 100644 --- a/app/utils.js +++ b/app/utils.js @@ -1,6 +1,4 @@ var Decimal = require("decimal.js"); -Decimal8 = Decimal.clone({ precision:8, rounding:8 }); - var env = require("./env.js"); var coins = require("./coins.js"); @@ -38,18 +36,6 @@ function hex2ascii(hex) { return str; } -function getBlockReward(blockHeight) { - var eras = [ new Decimal8(50) ]; - for (var i = 1; i < 34; i++) { - var previous = eras[i - 1]; - eras.push(new Decimal8(previous).dividedBy(2)); - } - - var index = Math.floor(blockHeight / 210000); - - return eras[index]; -} - function splitArrayIntoChunks(array, chunkSize) { var j = array.length; var chunks = []; @@ -160,7 +146,6 @@ module.exports = { doSmartRedirect: doSmartRedirect, redirectToConnectPageIfNeeded: redirectToConnectPageIfNeeded, hex2ascii: hex2ascii, - getBlockReward: getBlockReward, splitArrayIntoChunks: splitArrayIntoChunks, getRandomString: getRandomString, formatBytes: formatBytes, diff --git a/views/includes/block-content.pug b/views/includes/block-content.pug index 93ea42f..0884c8f 100644 --- a/views/includes/block-content.pug +++ b/views/includes/block-content.pug @@ -135,14 +135,14 @@ div(class="tab-content") tbody if (tx.vin[0].coinbase) - - totalInputValue = totalInputValue.plus(new Decimal(utils.getBlockReward(result.getblock.height))); + - totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(result.getblock.height))); tr th 1 td span(class="tag monospace") coinbase span(class="monospace") Newly minted coins td - - var currencyValue = utils.getBlockReward(result.getblock.height); + - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height); include ./value-display.pug each txInput, txInputIndex in result.txInputsByTransaction[tx.txid] diff --git a/views/transaction.pug b/views/transaction.pug index dd6cfd3..422906a 100644 --- a/views/transaction.pug +++ b/views/transaction.pug @@ -27,7 +27,7 @@ block content - var totalInputValue = new Decimal(0); if (result.getrawtransaction.vin[0].coinbase) - - totalInputValue = totalInputValue.plus(new Decimal(utils.getBlockReward(result.getblock.height))); + - totalInputValue = totalInputValue.plus(new Decimal(coinConfig.blockRewardFunction(result.getblock.height))); each txInput, txInputIndex in result.txInputs if (txInput) - var vout = txInput.vout[result.getrawtransaction.vin[txInputIndex].vout]; @@ -166,7 +166,7 @@ block content span(class="tag monospace") coinbase span(class="monospace") Newly minted coins td - - var currencyValue = utils.getBlockReward(result.getblock.height); + - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height); include includes/value-display.pug each txInput, txInputIndex in result.txInputs