diff --git a/blockchain.py b/blockchain.py index 386e61b..f9bdb1a 100644 --- a/blockchain.py +++ b/blockchain.py @@ -1,11 +1,10 @@ +# -*- coding: utf-8 -*- import hashlib import json from textwrap import dedent from time import time from uuid import uuid4 - - class Blockchain(object): def __init__(self): @@ -14,7 +13,7 @@ def __init__(self): # Create the genesis block genesis_block = self.new_block(previous_hash=1, proof=100) - self.chain.append(genesis_block) + #self.chain.append(genesis_block) def new_block(self, proof, previous_hash=None): block = { @@ -56,7 +55,7 @@ def hash(block): @staticmethod # Hashing algo section def valid_proof(last_proof, proof): - guess = f'{last_proof}{proof}'.encode() + guess = (str(last_proof)+str(proof)).encode() guess_hash = hashlib.sha256(guess).hexdigest() return guess_hash[:2] == "ff" @@ -72,20 +71,19 @@ def proof_of_work(last_proof): proof = 0 while True: - guess = f'{last_proof}{proof}'.encode() + guess = (str(last_proof)+str(proof)).encode() guess_hash = hashlib.sha256(guess).hexdigest() - if guess_hash[:2] == "ff": + if guess_hash[:2] == "00": break proof += 1 - print(dedent(f''' + print(dedent(''' New Proof found! - - New Proof: {proof} + New Proof: {proof} Last Proof: {last_proof} - Hash: {guess_hash} - ''')) + Hash: {guess_hash} + ''')) return proof diff --git a/blockchain.pyc b/blockchain.pyc new file mode 100644 index 0000000..44be147 Binary files /dev/null and b/blockchain.pyc differ