Created
February 19, 2020 14:05
-
-
Save metacoin/7ac7f8655a4468a2079a935c20982ef2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var BASE_REWARD = 10000000000; | |
function getReward(height, interval) { | |
const halvings = Math.floor(height / interval); | |
// BIP 42 (well, our own version of it, | |
// since we can only handle 32 bit shifts). | |
// https://github.com/bitcoin/bips/blob/master/bip-0042.mediawiki | |
if (halvings >= 34) | |
return 0; | |
// We need to shift right by `halvings`, | |
// but 50 btc is a 33 bit number, so we | |
// cheat. We only start halving once the | |
// halvings are at least 1. | |
if (halvings === 0) | |
return BASE_REWARD; | |
let rewardValue = BASE_REWARD; | |
for (let i = 0; i < halvings; i++){ | |
rewardValue /= 2; | |
} | |
return rewardValue; | |
}; | |
var height = 1; | |
var interval = 150; | |
for (var i = 0; i < 36; i++) { | |
console.log("Height: " + height + " || Halvings: " + Math.floor(height / interval) + " || Reward: " + getReward(height, interval)) | |
height+=150; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment