ui: Improve rpc page.
This commit is contained in:
parent
2922b171a6
commit
c5bd58afc2
@ -6,6 +6,7 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import shlex
|
||||
import traceback
|
||||
import threading
|
||||
import http.client
|
||||
@ -17,6 +18,7 @@ from . import __version__
|
||||
from .util import (
|
||||
dumpj,
|
||||
ensure,
|
||||
toBool,
|
||||
zeroIfNone,
|
||||
LockedCoinError,
|
||||
format_timestamp,
|
||||
@ -94,6 +96,31 @@ def listExplorerActions(swap_client):
|
||||
return actions
|
||||
|
||||
|
||||
def parse_cmd(cmd: str, type_map: str):
|
||||
params = shlex.split(cmd)
|
||||
if len(params) < 1:
|
||||
return '', []
|
||||
method = params[0]
|
||||
typed_params = []
|
||||
params = params[1:]
|
||||
|
||||
for i, param in enumerate(params):
|
||||
if i >= len(type_map):
|
||||
type_ind = 's'
|
||||
else:
|
||||
type_ind = type_map[i]
|
||||
if type_ind == 'i':
|
||||
typed_params.append(int(param))
|
||||
elif type_ind == 'b':
|
||||
typed_params.append(toBool(param))
|
||||
elif type_ind == 'j':
|
||||
typed_params.append(json.loads(param))
|
||||
else:
|
||||
typed_params.append(param)
|
||||
|
||||
return method, typed_params
|
||||
|
||||
|
||||
class HttpHandler(BaseHTTPRequestHandler):
|
||||
|
||||
def log_error(self, format, *args):
|
||||
@ -251,22 +278,28 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
result = None
|
||||
coin_type = -1
|
||||
coin_id = -1
|
||||
call_type = 'cli'
|
||||
type_map = ''
|
||||
messages = []
|
||||
err_messages = []
|
||||
form_data = self.checkForm(post_string, 'rpc', err_messages)
|
||||
if form_data:
|
||||
try:
|
||||
coin_id = int(form_data[b'coin_type'][0])
|
||||
if coin_id in (-2, -3, -4):
|
||||
coin_type = Coins(Coins.XMR)
|
||||
else:
|
||||
coin_type = Coins(coin_id)
|
||||
except Exception:
|
||||
raise ValueError('Unknown Coin Type')
|
||||
call_type = get_data_entry_or(form_data, 'call_type', 'cli')
|
||||
type_map = get_data_entry_or(form_data, 'type_map', '')
|
||||
try:
|
||||
coin_id = int(get_data_entry(form_data, 'coin_type'))
|
||||
if coin_id in (-2, -3, -4):
|
||||
coin_type = Coins(Coins.XMR)
|
||||
else:
|
||||
coin_type = Coins(coin_id)
|
||||
except Exception:
|
||||
raise ValueError('Unknown Coin Type')
|
||||
|
||||
cmd = form_data[b'cmd'][0].decode('utf-8')
|
||||
|
||||
try:
|
||||
try:
|
||||
cmd = get_data_entry(form_data, 'cmd')
|
||||
except Exception:
|
||||
raise ValueError('Invalid command')
|
||||
if coin_type == Coins.XMR:
|
||||
ci = swap_client.ci(coin_type)
|
||||
arr = cmd.split(None, 1)
|
||||
@ -284,7 +317,11 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
raise ValueError('Unknown XMR RPC variant')
|
||||
result = json.dumps(rv, indent=4)
|
||||
else:
|
||||
result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
|
||||
if call_type == 'http':
|
||||
method, params = parse_cmd(cmd, type_map)
|
||||
result = cmd + '\n' + swap_client.ci(coin_type).rpc_callback(method, params)
|
||||
else:
|
||||
result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
|
||||
except Exception as ex:
|
||||
result = str(ex)
|
||||
if self.server.swap_client.debug is True:
|
||||
@ -303,6 +340,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
'err_messages': err_messages,
|
||||
'coins': coins,
|
||||
'coin_type': coin_id,
|
||||
'call_type': call_type,
|
||||
'result': result,
|
||||
'messages': messages,
|
||||
'summary': summary,
|
||||
|
@ -73,6 +73,16 @@
|
||||
<input class="w-full aappearance-none bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 w-full block p-2.5" type="text" name="cmd">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="py-4 px-6 w-1/3 bold">
|
||||
<select class="appearance-none bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" name="call_type">
|
||||
<option value="cli" {% if call_type=="cli" %} selected{% endif %}>CLI</option>
|
||||
<option value="http" {% if call_type=="http" %} selected{% endif %}>HTTP</option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="py-4 pr-5 w-2/3">
|
||||
<input class="w-full aappearance-none bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 w-full block p-2.5" type="text" name="type_map">
|
||||
</td>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@ -112,4 +122,4 @@
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user