started rpc page.

This commit is contained in:
tecnovert 2019-07-27 23:14:28 +02:00
parent 4972f1f60f
commit cf73707643
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
6 changed files with 88 additions and 10 deletions

View file

@ -1,3 +1,3 @@
name = "basicswap" name = "basicswap"
__version__ = "0.0.1" __version__ = "0.0.2"

View file

@ -2319,11 +2319,23 @@ class BasicSwap():
def calltx(self, cmd): def calltx(self, cmd):
bindir = self.coin_clients[Coins.PART]['bindir'] bindir = self.coin_clients[Coins.PART]['bindir']
command_cli = os.path.join(bindir, cfg.PARTICL_TX) command_tx = os.path.join(bindir, cfg.PARTICL_TX)
chainname = '' if self.chain == 'mainnet' else (' -' + self.chain) chainname = '' if self.chain == 'mainnet' else (' -' + self.chain)
args = command_cli + chainname + ' ' + cmd args = command_tx + chainname + ' ' + cmd
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out = p.communicate() out = p.communicate()
if len(out[1]) > 0: if len(out[1]) > 0:
raise ValueError('TX error ' + str(out[1])) raise ValueError('TX error ' + str(out[1]))
return out[0].decode('utf-8').strip() return out[0].decode('utf-8').strip()
def callcoincli(self, coin_type, params, wallet=None):
bindir = self.coin_clients[coin_type]['bindir']
datadir = self.coin_clients[coin_type]['datadir']
command_cli = os.path.join(bindir, chainparams[coin_type]['name'] + '-cli')
chainname = '' if self.chain == 'mainnet' else (' -' + self.chain)
args = command_cli + chainname + ' ' + '-datadir=' + datadir + ' ' + params
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out = p.communicate()
if len(out[1]) > 0:
raise ValueError('CLI error ' + str(out[1]))
return out[0].decode('utf-8').strip()

View file

@ -126,6 +126,44 @@ class HttpHandler(BaseHTTPRequestHandler):
def js_index(self, url_split): def js_index(self, url_split):
return bytes(json.dumps(self.server.swap_client.getSummary()), 'UTF-8') return bytes(json.dumps(self.server.swap_client.getSummary()), 'UTF-8')
def page_rpc(self, url_split, post_string):
swap_client = self.server.swap_client
result = None
messages = []
if post_string != '':
form_data = urllib.parse.parse_qs(post_string)
form_id = form_data[b'formid'][0].decode('utf-8')
if self.server.last_form_id.get('rpc', None) == form_id:
messages.append('Prevented double submit for form {}.'.format(form_id))
else:
self.server.last_form_id['newoffer'] = form_id
try:
coin_type = Coins(int(form_data[b'coin_type'][0]))
except Exception:
raise ValueError('Unknown Coin Type')
cmd = form_data[b'cmd'][0].decode('utf-8')
try:
result = swap_client.callcoincli(coin_type, cmd)
except Exception as ex:
result = str(ex)
coins = []
for k, v in swap_client.coin_clients.items():
if v['connection_type'] == 'rpc':
coins.append((int(k), getCoinName(k)))
template = env.get_template('rpc.html')
return bytes(template.render(
title=self.server.title,
h2=self.server.title,
coins=coins,
result=result,
form_id=os.urandom(8).hex(),
), 'UTF-8')
def page_active(self, url_split, post_string): def page_active(self, url_split, post_string):
swap_client = self.server.swap_client swap_client = self.server.swap_client
active_swaps = swap_client.listSwapsInProgress() active_swaps = swap_client.listSwapsInProgress()
@ -141,9 +179,6 @@ class HttpHandler(BaseHTTPRequestHandler):
def page_wallets(self, url_split, post_string): def page_wallets(self, url_split, post_string):
swap_client = self.server.swap_client swap_client = self.server.swap_client
content = html_content_start(self.server.title, self.server.title) \
+ '<h3>Wallets</h3>'
messages = [] messages = []
if post_string != '': if post_string != '':
form_data = urllib.parse.parse_qs(post_string) form_data = urllib.parse.parse_qs(post_string)
@ -535,6 +570,8 @@ class HttpHandler(BaseHTTPRequestHandler):
return self.page_active(url_split, post_string) return self.page_active(url_split, post_string)
if url_split[1] == 'wallets': if url_split[1] == 'wallets':
return self.page_wallets(url_split, post_string) return self.page_wallets(url_split, post_string)
if url_split[1] == 'rpc':
return self.page_rpc(url_split, post_string)
if url_split[1] == 'offer': if url_split[1] == 'offer':
return self.page_offer(url_split, post_string) return self.page_offer(url_split, post_string)
if url_split[1] == 'offers': if url_split[1] == 'offers':

View file

@ -1,7 +1,5 @@
{% include 'header.html' %} {% include 'header.html' %}
<p><a href="/wallets">View Wallets</a></p>
<p> <p>
{% if refresh %} {% if refresh %}
Page Refresh: {{ refresh }} seconds<br/> Page Refresh: {{ refresh }} seconds<br/>
@ -9,6 +7,9 @@ Page Refresh: {{ refresh }} seconds<br/>
Version: {{ version }} Version: {{ version }}
</p> </p>
<p> <p>
<a href="/wallets">View Wallets</a><br/>
<a href="/rpc">RPC Console</a><br/>
<br/>
<a href="/active">Swaps in progress: {{ summary.num_swapping }}</a><br/> <a href="/active">Swaps in progress: {{ summary.num_swapping }}</a><br/>
<a href="/offers">Network Offers: {{ summary.num_network_offers }}</a><br/> <a href="/offers">Network Offers: {{ summary.num_network_offers }}</a><br/>
<a href="/sentoffers">Sent Offers: {{ summary.num_sent_offers }}</a><br/> <a href="/sentoffers">Sent Offers: {{ summary.num_sent_offers }}</a><br/>

View file

@ -13,7 +13,7 @@
{% for c in coins %} {% for c in coins %}
<option value="{{ c[0] }}">{{ c[1] }}</option> <option value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %} {% endfor %}
</select>' </select>
</td><td>Amount From</td><td><input type="text" name="amt_from"></td></tr> </td><td>Amount From</td><td><input type="text" name="amt_from"></td></tr>
<tr><td>Coin To</td><td> <tr><td>Coin To</td><td>
@ -21,7 +21,7 @@
{% for c in coins %} {% for c in coins %}
<option value="{{ c[0] }}">{{ c[1] }}</option> <option value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %} {% endfor %}
</select>' </select>
</td><td>Amount To</td><td><input type="text" name="amt_to"></td></tr> </td><td>Amount To</td><td><input type="text" name="amt_to"></td></tr>
<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="2" max="96" value="48"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr> <tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="2" max="96" value="48"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr>

View file

@ -0,0 +1,28 @@
{% include 'header.html' %}
<h3>New Offer</h3>
{% for m in messages %}
<p>{{ m }}</p>
{% endfor %}
<form method="post">
<p>
<select name="coin_type"><option value="-1">-- Select Coin --</option>
{% for c in coins %}
<option value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %}
</select><br/>
<input type="text" name="cmd"><br/>
<input type="submit" value="Submit">
<input type="hidden" name="formid" value="{{ form_id }}">
</p>
</form>
{% if result %}
<textarea id="story" name="story" rows="40" cols="160">
{{ result }}
</textarea>
{% endif %}
<p><a href="/">home</a></p>
</body></html>