Browse Source

use coin-specific block-reward schedule (litecoin was wrong)

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
9ee84ccc2c
  1. 14
      app/coins/btc.js
  2. 14
      app/coins/ltc.js
  3. 15
      app/utils.js
  4. 4
      views/includes/block-content.pug
  5. 4
      views/transaction.pug

14
app/coins/btc.js

@ -1,3 +1,6 @@
var Decimal = require("decimal.js");
Decimal8 = Decimal.clone({ precision:8, rounding:8 });
module.exports = { module.exports = {
name:"Bitcoin", name:"Bitcoin",
logoUrl:"/img/logo/btc.svg", logoUrl:"/img/logo/btc.svg",
@ -161,5 +164,16 @@ module.exports = {
return -1; 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];
} }
}; };

14
app/coins/ltc.js

@ -1,3 +1,6 @@
var Decimal = require("decimal.js");
Decimal8 = Decimal.clone({ precision:8, rounding:8 });
module.exports = { module.exports = {
name:"Litecoin", name:"Litecoin",
logoUrl:"/img/logo/ltc.svg", logoUrl:"/img/logo/ltc.svg",
@ -82,5 +85,16 @@ module.exports = {
return -1; 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];
} }
}; };

15
app/utils.js

@ -1,6 +1,4 @@
var Decimal = require("decimal.js"); var Decimal = require("decimal.js");
Decimal8 = Decimal.clone({ precision:8, rounding:8 });
var env = require("./env.js"); var env = require("./env.js");
var coins = require("./coins.js"); var coins = require("./coins.js");
@ -38,18 +36,6 @@ function hex2ascii(hex) {
return str; 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) { function splitArrayIntoChunks(array, chunkSize) {
var j = array.length; var j = array.length;
var chunks = []; var chunks = [];
@ -160,7 +146,6 @@ module.exports = {
doSmartRedirect: doSmartRedirect, doSmartRedirect: doSmartRedirect,
redirectToConnectPageIfNeeded: redirectToConnectPageIfNeeded, redirectToConnectPageIfNeeded: redirectToConnectPageIfNeeded,
hex2ascii: hex2ascii, hex2ascii: hex2ascii,
getBlockReward: getBlockReward,
splitArrayIntoChunks: splitArrayIntoChunks, splitArrayIntoChunks: splitArrayIntoChunks,
getRandomString: getRandomString, getRandomString: getRandomString,
formatBytes: formatBytes, formatBytes: formatBytes,

4
views/includes/block-content.pug

@ -135,14 +135,14 @@ div(class="tab-content")
tbody tbody
if (tx.vin[0].coinbase) 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 tr
th 1 th 1
td td
span(class="tag monospace") coinbase span(class="tag monospace") coinbase
span(class="monospace") Newly minted coins span(class="monospace") Newly minted coins
td td
- var currencyValue = utils.getBlockReward(result.getblock.height); - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height);
include ./value-display.pug include ./value-display.pug
each txInput, txInputIndex in result.txInputsByTransaction[tx.txid] each txInput, txInputIndex in result.txInputsByTransaction[tx.txid]

4
views/transaction.pug

@ -27,7 +27,7 @@ block content
- var totalInputValue = new Decimal(0); - var totalInputValue = new Decimal(0);
if (result.getrawtransaction.vin[0].coinbase) 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 each txInput, txInputIndex in result.txInputs
if (txInput) if (txInput)
- var vout = txInput.vout[result.getrawtransaction.vin[txInputIndex].vout]; - var vout = txInput.vout[result.getrawtransaction.vin[txInputIndex].vout];
@ -166,7 +166,7 @@ block content
span(class="tag monospace") coinbase span(class="tag monospace") coinbase
span(class="monospace") Newly minted coins span(class="monospace") Newly minted coins
td td
- var currencyValue = utils.getBlockReward(result.getblock.height); - var currencyValue = coinConfig.blockRewardFunction(result.getblock.height);
include includes/value-display.pug include includes/value-display.pug
each txInput, txInputIndex in result.txInputs each txInput, txInputIndex in result.txInputs

Loading…
Cancel
Save