blockchain practical, Assignments of Database Management Systems (DBMS)

this is about blockchain practical

Typology: Assignments

2019/2020

Uploaded on 12/07/2020

theoneday
theoneday 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Blockchain Lab 5
Name: Abhinav ukey
Roll no: 192010004
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()
pf3
pf4

Partial preview of the text

Download blockchain practical and more Assignments Database Management Systems (DBMS) in PDF only on Docsity!

Name: Abhinav ukey

Roll no: 192010004

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()

Name: Abhinav ukey

Roll no: 192010004

Output: Data in Json format for main_block Header Info for main_block

Name: Abhinav ukey

Roll no: 192010004

main_block & get_chain in mobile phone