-
Notifications
You must be signed in to change notification settings - Fork 111
/
web.py
49 lines (43 loc) · 1.3 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
46
47
48
49
# -*- 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 index():
return render_template('guide.html')
@app.route('/allblocks')
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)