-
Notifications
You must be signed in to change notification settings - Fork 0
/
gottalight.py
182 lines (143 loc) · 5.79 KB
/
gottalight.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import subprocess
import json
from flask import Flask
from flask import request
from flask import send_file
from flask import Response
from flask_qrcode import QRcode
app = Flask( __name__ , static_url_path='')
qrcode = QRcode(app)
@app .route( "/" )
def index():
return app.send_static_file('gottalight_gui.html')
@app .route( "/getinfo" )
def getinfo():
return Response(subprocess.check_output(['lightning-cli', 'getinfo']),mimetype='application/json')
@app .route( "/listpeers" )
def listpeers():
return Response(subprocess.check_output(['lightning-cli', 'listpeers']),mimetype='application/json')
@app .route( "/listfunds" )
def listfunds():
return Response(subprocess.check_output(['lightning-cli', 'listfunds']),mimetype='application/json')
@app .route( "/listinvoices" )
def listinvoices():
return Response(subprocess.check_output(['lightning-cli', 'listinvoices']),mimetype='application/json')
@app .route( "/invoice" )
def invoice():
p1=request.args.get("amount")
p2=request.args.get("label")
p3=request.args.get("desc")
resp = "["
try:
invoice=(subprocess.check_output(['lightning-cli','invoice', p1, p2, p3],stderr=subprocess.STDOUT)).decode('utf-8')
bolt11 = json.loads(invoice)['bolt11']
resp+="\""+bolt11+"\""
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route( "/invoiceqr" )
def invoiceqr():
p1=request.args.get("amount")
p2=request.args.get("label")
p3=request.args.get("desc")
bolt11 = "ERROR"
resp = "["
try:
invoice=(subprocess.check_output(['lightning-cli','invoice', p1, p2, p3],stderr=subprocess.STDOUT)).decode('utf-8')
bolt11 = json.loads(invoice)['bolt11']
resp+="\""+qrcode(bolt11,border=10)+"\""
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/waitinvoice")
def waitinvoice():
p1=request.args.get("bolt11")
return Response(subprocess.check_output(['lightning-cli','waitinvoice',p1]),mimetype='application/json')
@app .route("/pay")
def pay():
bolt11=request.args.get("bolt11")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','pay', bolt11],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/delexpiredinvoice")
def delexpiredinvoce():
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','delexpiredinvoice'],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/getlog")
def getlog():
return Response(subprocess.check_output(['lightning-cli','getlog']),mimetype='application/json')
@app .route("/listconfigs")
def listconfigs():
return Response(subprocess.check_output(['lightning-cli','listconfigs']),mimetype='application/json')
@app .route("/listforwards")
def listforwards():
return Response(subprocess.check_output(['lightning-cli','listforwards']),mimetype='application/json')
@app .route("/devrescanoutputs")
def devrescanoutputs():
return Response(subprocess.check_output(['lightning-cli','dev-rescan-outputs']),mimetype='application/json')
@app .route("/connect")
def connect():
p1=request.args.get("id")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','connect', p1],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/close")
def closeid():
p1=request.args.get("id")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','close', p1],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/disconnect")
def disconnect():
p1=request.args.get("id")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','disconnect', p1],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/fundchannel")
def fundchannel():
p1=request.args.get("id")
p2=request.args.get("amount")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','fundchannel', p1,p2],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
@app .route("/getroute")
def getroute():
node_id=request.args.get("node_id")
msatoshi=request.args.get("msatoshi")
riskfactor=request.args.get("riskfactor")
resp = "["
try:
resp+=(subprocess.check_output(['lightning-cli','getroute', node_id,msatoshi,riskfactor],stderr=subprocess.STDOUT)).decode('utf-8')
resp+=", \"SUCCESS\"]"
except subprocess.CalledProcessError as e:
resp+=e.output.decode('utf-8')+", \"ERROR\"]"
return Response(resp,mimetype='application/json')
if __name__ == "__main__" :
app.run( host = '0.0.0.0' , debug = True )