Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions blockchain.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 = {
Expand Down Expand Up @@ -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"

Expand All @@ -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


Expand Down
Binary file added blockchain.pyc
Binary file not shown.