forked from daxeel/blockshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
45 lines (40 loc) · 1.22 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
# ==================================================
# ==================== META DATA ===================
# ==================================================
__author__ = "Daxeel Soni"
__url__ = "https://daxeel.github.io"
__email__ = "[email protected]"
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "Daxeel Soni"
# ==================================================
# ================= IMPORT MODULES =================
# ==================================================
from flask import Flask, render_template, jsonify
import json
# Init flask app
app = Flask(__name__)
@app.route('/')
def mined_blocks():
"""
Endpoint to list all mined blocks.
"""
f = open("chain.txt", "r")
data = json.loads(f.read())
f.close()
return render_template('blocks.html', data=data)
@app.route('/block/<hash>')
def block(hash):
"""
Endpoint which shows all the data for given block hash.
"""
f = open("chain.txt", "r")
data = json.loads(f.read())
f.close()
for eachBlock in data:
if eachBlock['hash'] == hash:
return render_template('blockdata.html', data=eachBlock)
# Run flask app
if __name__ == '__main__':
app.run(debug=True)