ui: Add XMR rpc variant options.

This commit is contained in:
tecnovert 2022-07-06 13:16:18 +02:00
parent 91e285bf4a
commit 1b7550ff76
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93

View File

@ -189,11 +189,16 @@ class HttpHandler(BaseHTTPRequestHandler):
result = None result = None
coin_type = -1 coin_type = -1
coin_id = -1
messages = [] messages = []
form_data = self.checkForm(post_string, 'rpc', messages) form_data = self.checkForm(post_string, 'rpc', messages)
if form_data: if form_data:
try: try:
coin_type = Coins(int(form_data[b'coin_type'][0])) 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: except Exception:
raise ValueError('Unknown Coin Type') raise ValueError('Unknown Coin Type')
@ -205,18 +210,37 @@ class HttpHandler(BaseHTTPRequestHandler):
arr = cmd.split(None, 1) arr = cmd.split(None, 1)
method = arr[0] method = arr[0]
params = json.loads(arr[1]) if len(arr) > 1 else [] params = json.loads(arr[1]) if len(arr) > 1 else []
result = json.dumps(ci.rpc_wallet_cb(method, params), indent=4) if coin_id == -4:
rv = ci.rpc_wallet_cb(method, params)
elif coin_id == -3:
rv = ci.rpc_cb(method, params)
elif coin_id == -2:
if params == []:
params = None
rv = ci.rpc_cb2(method, params)
else:
raise ValueError('Unknown XMR RPC variant')
result = json.dumps(rv, indent=4)
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:
result = str(ex) result = str(ex)
if self.server.swap_client.debug is True:
self.server.swap_client.log.error(traceback.format_exc())
template = env.get_template('rpc.html') template = env.get_template('rpc.html')
coins = listAvailableCoins(swap_client, with_variants=False)
coins = [c for c in coins if c[0] != Coins.XMR]
coins.append((-2, 'Monero'))
coins.append((-3, 'Monero JSON'))
coins.append((-4, 'Monero Wallet'))
return bytes(template.render( return bytes(template.render(
title=self.server.title, title=self.server.title,
h2=self.server.title, h2=self.server.title,
coins=listAvailableCoins(swap_client, with_variants=False), coins=coins,
coin_type=coin_type, coin_type=coin_id,
result=result, result=result,
messages=messages, messages=messages,
form_id=os.urandom(8).hex(), form_id=os.urandom(8).hex(),