Blockchain Using Python Lect_3
Blockchain Using Python Lect_3
# For timestamp
import datetime
class Blockchain:
return new_proof
def hash(self, block):
encoded_block = json.dumps(block,
sort_keys=True).encode()
return hashlib.sha256(encoded_block).hexdigest()
def chain_valid(self, chain):
previous_block = chain[0]
block_index = 1
if hash_operation[:5] != '00000':
return False
previous_block = block
block_index += 1
return True
# Creating the Web App using flask
app = Flask(__name__)
if valid:
response = {'message': 'The Blockchain is
valid.'}
else:
response = {'message': 'The Blockchain is not
valid.'}
return jsonify(response), 200
# Run the flask server locally
app.run(host='127.0.0.1',
port=5000)
Output (mine_block):
{"message":"The Blockchain is
valid."}