ui: Improve rpc page.
This commit is contained in:
parent
2922b171a6
commit
c5bd58afc2
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import shlex
|
||||||
import traceback
|
import traceback
|
||||||
import threading
|
import threading
|
||||||
import http.client
|
import http.client
|
||||||
@ -17,6 +18,7 @@ from . import __version__
|
|||||||
from .util import (
|
from .util import (
|
||||||
dumpj,
|
dumpj,
|
||||||
ensure,
|
ensure,
|
||||||
|
toBool,
|
||||||
zeroIfNone,
|
zeroIfNone,
|
||||||
LockedCoinError,
|
LockedCoinError,
|
||||||
format_timestamp,
|
format_timestamp,
|
||||||
@ -94,6 +96,31 @@ def listExplorerActions(swap_client):
|
|||||||
return actions
|
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):
|
class HttpHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def log_error(self, format, *args):
|
def log_error(self, format, *args):
|
||||||
@ -251,12 +278,17 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
result = None
|
result = None
|
||||||
coin_type = -1
|
coin_type = -1
|
||||||
coin_id = -1
|
coin_id = -1
|
||||||
|
call_type = 'cli'
|
||||||
|
type_map = ''
|
||||||
messages = []
|
messages = []
|
||||||
err_messages = []
|
err_messages = []
|
||||||
form_data = self.checkForm(post_string, 'rpc', err_messages)
|
form_data = self.checkForm(post_string, 'rpc', err_messages)
|
||||||
if form_data:
|
if form_data:
|
||||||
try:
|
try:
|
||||||
coin_id = int(form_data[b'coin_type'][0])
|
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):
|
if coin_id in (-2, -3, -4):
|
||||||
coin_type = Coins(Coins.XMR)
|
coin_type = Coins(Coins.XMR)
|
||||||
else:
|
else:
|
||||||
@ -264,9 +296,10 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError('Unknown Coin Type')
|
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:
|
if coin_type == Coins.XMR:
|
||||||
ci = swap_client.ci(coin_type)
|
ci = swap_client.ci(coin_type)
|
||||||
arr = cmd.split(None, 1)
|
arr = cmd.split(None, 1)
|
||||||
@ -283,6 +316,10 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Unknown XMR RPC variant')
|
raise ValueError('Unknown XMR RPC variant')
|
||||||
result = json.dumps(rv, indent=4)
|
result = json.dumps(rv, indent=4)
|
||||||
|
else:
|
||||||
|
if call_type == 'http':
|
||||||
|
method, params = parse_cmd(cmd, type_map)
|
||||||
|
result = cmd + '\n' + swap_client.ci(coin_type).rpc_callback(method, params)
|
||||||
else:
|
else:
|
||||||
result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
|
result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@ -303,6 +340,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
'err_messages': err_messages,
|
'err_messages': err_messages,
|
||||||
'coins': coins,
|
'coins': coins,
|
||||||
'coin_type': coin_id,
|
'coin_type': coin_id,
|
||||||
|
'call_type': call_type,
|
||||||
'result': result,
|
'result': result,
|
||||||
'messages': messages,
|
'messages': messages,
|
||||||
'summary': summary,
|
'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">
|
<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>
|
</td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user