


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
this is about blockchain practical
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Deploy block mining application over server. Also execute via mobile or other device(s) Code: #Deploy block mining application over server. Also execute via mobile or other device(s) also import hashlib import json from flask import Flask class blockchain: def init(self): self.chain = [] self.create_block(previous_hash = 0) def create_block(self, previous_hash): block = { 'index': len(self.chain) + 1, 'previous_hash' : previous_hash } self.chain.append(block) return block def hash(self, block): encode_block = json.dumps(block).encode() return hashlib.sha256(encode_block).hexdigest() def get_previous_block(self): return self.chain[-1] app = Flask(name) blk = blockchain() @app.route('/main_block') def mine_block(): previous_block = blk.get_previous_block() previous_hash = blk.hash(previous_block) block = blk.create_block(previous_hash) response = { 'Message' : 'Your block is mined', 'index' : block['index'], 'previous_hash' : block['previous_hash'] } return response @app.route('/get_chain') def get_chain(): response = { 'chain' : blk.chain, 'length' : len(blk.chain) } return response app.run()
Output: Data in Json format for main_block Header Info for main_block
main_block & get_chain in mobile phone