From 8828882153c83e769502f46f60bbb71d528b321b Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Fri, 29 Aug 2014 10:51:02 -0400 Subject: [PATCH] added max_money.py code example --- ch08.asciidoc | 23 +++++++++++++++++++++++ code/max_money.py | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 code/max_money.py diff --git a/ch08.asciidoc b/ch08.asciidoc index 89b2cd0e..5d4ddf08 100644 --- a/ch08.asciidoc +++ b/ch08.asciidoc @@ -18,6 +18,29 @@ In this chapter, we will first examine mining as a monetary supply mechanism and Bitcoins are "minted" during the creation of each block at a fixed and diminishing rate. Each block, generated on average every 10 minutes, contains entirely new bitcoins, created from nothing. Every 210,000 blocks or approximately every four years the currency issuance rate is decreased by 50%. For the first four years of operation of the network, each block contained 50 new bitcoin. In November of 2012, the new bitcoin issuance rate was decreased to 25 bitcoin per block and it will decrease again to 12.5 bitcoin at block 420,000, which will be mined sometime in 2016. The rate of new coins decreases like this exponentially over 64 "halvings", until block 13,230,000 (mined approximately in year 2137) when it reaches the minimum currency unit of 1 satoshi. Finally, after 13.44 million blocks, in approximately 2140, all 2,099,999,997,690,000 satoshis, or almost 21 million bitcoin will be issued. Thereafter, blocks will contain no new bitcoin, and miners will be rewarded solely through the transaction fees. +In the example code below, we calculate the total amount of bitcoin that will be issued: + +[[max_money]] +.A script for calculating how much total bitcoin will be issued +==== +[source, python] +---- +include::code/max_money.py[] +---- +==== + +Running the script: + +[[max_money_run]] +.Running the max_money.py script +==== +[source,bash] +---- +$ python max_money.py +Total BTC to ever be created: 2099999997690000 Satoshis +---- +==== + [[bitcoin_money_supply]] .Supply of bitcoin currency over time based on a geometrically decreasing issuance rate image::images/BitcoinMoneySupply.png["BitcoinMoneySupply"] diff --git a/code/max_money.py b/code/max_money.py new file mode 100644 index 00000000..a54238b4 --- /dev/null +++ b/code/max_money.py @@ -0,0 +1,16 @@ +# Original block reward for miners was 50 BTC +start_block_reward = 50 +# 210000 is around every 4 years with a 10 minute block interval +reward_interval = 210000 + +def max_money(): + # 50 BTC = 50 0000 0000 Satoshis + current_reward = 50 * 10**8 + total = 0 + while current_reward > 0: + total += reward_interval * current_reward + current_reward /= 2 + return total + +print "Total BTC to ever be created:", max_money(), "Satoshis" +