This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
112 lines (95 loc) · 2.76 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from unittest import result
from waitress import serve
from flask import Flask, jsonify, render_template
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
app = Flask(__name__)
apiversion = 2.0
username = "rpcusername"
password = "rpcpassword"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/apiinfo")
def apiinfo():
return jsonify({
"apiver": apiversion,
"result": {
"id": "bkc-rest-api",
"version": apiversion,
"description": "Bunkercoin REST API Alpha 2.0",
"author": "The Bunkercoin Project"
}
})
@app.route("/blockcount")
def blockcount():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getblockcount()
return jsonify({
"apiver": apiversion,
"result": {
"blockcount": result
}
})
@app.route("/blockbyheight/<int:height>")
def blockbyheight(height):
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
tx = rpc_connection.getblockhash(height)
result = rpc_connection.getblock(tx)
return jsonify({
"apiver": apiversion,
"result": {
"block": result
}
})
@app.route("/hashrate")
def hashrate():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getnetworkhashps()
return jsonify({
"apiver": apiversion,
"result": {
"hashrate": result
}
})
@app.route("/diff")
def diff():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getdifficulty()
return jsonify({
"apiver": apiversion,
"result": {
"difficulty": result
}
})
@app.route("/meminfo")
def meminfo():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getmempoolinfo()
return jsonify({
"apiver": apiversion,
"result": {
"mempool": result
}
})
@app.route("/info")
def info():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getinfo()
return jsonify({
"apiver": apiversion,
"result": {
"info": result
}
})
@app.route("/blockchaininfo")
def blockchaininfo():
rpc_connection = AuthServiceProxy(f"http://{username}:{password}@127.0.0.1:22555")
result = rpc_connection.getblockchaininfo()
return jsonify({
"apiver": apiversion,
"result": {
"info": result
}
})
if __name__ == "__main__":
serve(app, port=5000) # run our Flask app