mooniversity_examples/bitcoin_blockreward_calculator.py

15 lines
714 B
Python
Raw Normal View History

2019-12-16 21:03:45 +03:00
from helpers import mainnet
from decimal import Decimal
2019-12-16 21:30:16 +03:00
def calculate_bitcoin_cycle_and_block_reward():
#This little program tells you the bitcoin's cycle count and the bitcoin block reward amount
2019-12-16 21:33:21 +03:00
INITIAL_SUBSIDY = Decimal(50)
BLOCKS_PER_HALVENING = 210000
2019-12-16 21:30:16 +03:00
last_block = mainnet.getblockchaininfo()["blocks"]
2019-12-16 21:33:21 +03:00
cycle_count = int(last_block/BLOCKS_PER_HALVENING)
block_reward = INITIAL_SUBSIDY / cycle_count*2
return {"Cycle":cycle_count+1, "Block_reward":block_reward}
2019-12-16 21:03:45 +03:00
2019-12-16 21:30:16 +03:00
if __name__ == "__main__":
cycle = calculate_bitcoin_cycle_and_block_reward()
print(f"Bitcoin is in the {cycle.get('Cycle')}. halvening cycle and the block reward is {cycle.get('Block_reward')} ₿ right now.")