From d91c8e9a2e5133ce9e6f6e478a5f8e0b7d8f0bf7 Mon Sep 17 00:00:00 2001 From: Efe Date: Mon, 16 Dec 2019 21:30:16 +0300 Subject: [PATCH 1/2] Changed the main code to a function --- bitcoin_blockreward_calculator.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bitcoin_blockreward_calculator.py b/bitcoin_blockreward_calculator.py index 7cbc282..7c225ea 100644 --- a/bitcoin_blockreward_calculator.py +++ b/bitcoin_blockreward_calculator.py @@ -1,12 +1,15 @@ from helpers import mainnet from decimal import Decimal -#This little program tells you the bitcoin's cycle count and the bitcoin block reward amount +def calculate_bitcoin_cycle_and_block_reward(): + #This little program tells you the bitcoin's cycle count and the bitcoin block reward amount + initial_subsidy = Decimal(50) + blocks_per_halvening = 210000 + last_block = mainnet.getblockchaininfo()["blocks"] + cycle_count = int(last_block/blocks_per_halvening) + initial_subsidy /= cycle_count*2 + return {"Cycle":cycle_count+1, "Block_reward":initial_subsidy} -initial_subsidy = Decimal(50) -blocks_per_halvening = 210000 -last_block = mainnet.getblockchaininfo()["blocks"] -cycle = int(last_block/blocks_per_halvening) -initial_subsidy /= cycle*2 - -print(f"Bitcoin is in the {cycle+1}. halvening cycle and the block reward is {initial_subsidy} btc right now.") \ No newline at end of file +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.") \ No newline at end of file From c6d2dada64875a8edec10b223677deb1e4e78643 Mon Sep 17 00:00:00 2001 From: Efe Date: Mon, 16 Dec 2019 21:33:21 +0300 Subject: [PATCH 2/2] Made the generic variables capital --- bitcoin_blockreward_calculator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bitcoin_blockreward_calculator.py b/bitcoin_blockreward_calculator.py index 7c225ea..739187f 100644 --- a/bitcoin_blockreward_calculator.py +++ b/bitcoin_blockreward_calculator.py @@ -3,12 +3,12 @@ from decimal import Decimal def calculate_bitcoin_cycle_and_block_reward(): #This little program tells you the bitcoin's cycle count and the bitcoin block reward amount - initial_subsidy = Decimal(50) - blocks_per_halvening = 210000 + INITIAL_SUBSIDY = Decimal(50) + BLOCKS_PER_HALVENING = 210000 last_block = mainnet.getblockchaininfo()["blocks"] - cycle_count = int(last_block/blocks_per_halvening) - initial_subsidy /= cycle_count*2 - return {"Cycle":cycle_count+1, "Block_reward":initial_subsidy} + cycle_count = int(last_block/BLOCKS_PER_HALVENING) + block_reward = INITIAL_SUBSIDY / cycle_count*2 + return {"Cycle":cycle_count+1, "Block_reward":block_reward} if __name__ == "__main__": cycle = calculate_bitcoin_cycle_and_block_reward()