-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeamon_ui.py
144 lines (117 loc) · 5.66 KB
/
deamon_ui.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
from flask import Flask, render_template, request, redirect, jsonify
from flask import redirect, request, url_for
import subprocess
from object.payment_info import PaymentInfo
app = Flask(__name__)
selected_wallet_name = ""
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get_status', methods=['POST'])
def get_status():
try:
command = 'curl -s --data-binary \'{"jsonrpc":"2.0","id":"1","method":"getstatus"}\' http://127.0.0.1:37128/ | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return json_output
except Exception as e:
print(f"Error: {e}")
return "An error occurred while processing the request.", 500
@app.route('/create_wallet', methods=['GET', 'POST'])
def create_wallet():
if request.method == 'POST':
wallet_name = request.form['wallet_name']
user_password = request.form['user_password']
try:
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"createwallet","params":["{wallet_name}", "{user_password}"]}}\' http://127.0.0.1:37128/ | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return redirect(url_for('index')) # Redirect to the index page with POST method
except Exception as e:
print(f"Error: {e}")
return "An error occurred while creating the wallet.", 500
return render_template('createwallet.html')
@app.route('/get_wallet_info', methods=['POST'])
def get_wallet_info():
try:
command = 'curl -s --data-binary \'{"jsonrpc":"2.0","id":"1","method":"getwalletinfo"}\' http://127.0.0.1:37128/ | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
print(f"Output: {json_output}")
return json_output
except Exception as e:
print(f"Error: {e}")
return "An error occurred while processing the request.", 500
@app.route('/select_wallet', methods=['GET', 'POST'])
def select_wallet():
if request.method == 'POST':
wallet_name = request.form['wallet_name']
global selected_wallet_name
selected_wallet_name = wallet_name
try:
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"selectwallet","params":["{wallet_name}", "true"]}}\' http://127.0.0.1:37128/ | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return redirect(url_for('index')) # Redirect to the index page with POST method
except Exception as e:
print(f"Error: {e}")
return "An error occurred while creating the wallet.", 500
return render_template('selectwallet.html')
@app.route('/generate_new_address', methods=['POST'])
def generate_new_address():
try:
global selected_wallet_name
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"getnewaddress","params":["Command line"]}}\' http://127.0.0.1:37128/{selected_wallet_name} | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
json_output = result.stdout.strip()
return json_output
else:
return 'Failed to generate new address', 500
except Exception as e:
print(f"Error: {e}")
return "An error occurred while generating a new address.", 500
@app.route('/send', methods=['GET', 'POST'])
def send():
if request.method == 'POST':
payments = PaymentInfo()
payments.Sendto = request.form['bitcoin_address']
payments.Amount = request.form['amount']
payments.Label = request.form['label']
coins = []
coins.append(request.form['outpoint'])
feeTarget = 1
password = "1234"
try:
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"send","params":["{payments}", "{coins}", "{feeTarget}", "{password}"]}}\' http://127.0.0.1:37128/ | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return redirect(url_for('index')) # Redirect to the index page with POST method
except Exception as e:
print(f"Error: {e}")
return "An error occurred while creating the wallet.", 500
return render_template('send.html')
@app.route('/list_unspent_coins', methods=['POST'])
def list_unspent_coins():
try:
global selected_wallet_name
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"listunspentcoins"}}\' http://127.0.0.1:37128/{selected_wallet_name} | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return json_output
except Exception as e:
print(f"Error: {e}")
return "An error occurred while processing the request.", 500
@app.route('/list_coins', methods=['POST'])
def list_coins():
try:
global selected_wallet_name
command = f'curl -s --data-binary \'{{"jsonrpc":"2.0","id":"1","method":"listcoins"}}\' http://127.0.0.1:37128/{selected_wallet_name} | jq'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
json_output = result.stdout
return json_output
except Exception as e:
print(f"Error: {e}")
return "An error occurred while processing the request.", 500
if __name__ == '__main__':
app.run(debug=True)