Skip to content

Instantly share code, notes, and snippets.

@dlio
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlio/69238ba37cae489a3650 to your computer and use it in GitHub Desktop.
Save dlio/69238ba37cae489a3650 to your computer and use it in GitHub Desktop.
Forumla -- Total Extant Bitcoins at a Given Block
# 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