Last active
August 29, 2015 14:01
-
-
Save dlio/69238ba37cae489a3650 to your computer and use it in GitHub Desktop.
Forumla -- Total Extant Bitcoins at a Given Block
This file contains 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
# bitcoin example, halving schedule | |
initial_reward = 50 | |
halving_period = 210000 | |
# given a block height, calculate number of bitcoins minted thus far | |
blocks = `bitcoind getblockcount` | |
# number of eras -- rounded up to nearest int | |
era_count = (blocks / halving_period).ceil | |
total_coins = 0 | |
# loop over each era | |
(1..era_count).each do |era| | |
if era == era_count | |
era_blocks = blocks % halving_period | |
else | |
era_blocks = halving_period | |
end | |
# reward halves each new era | |
total_coins = total_coins + (initial_reward * 0.5^(era - 1) * era_blocks) | |
end | |
puts total_coins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment