diff --git a/basicswap/__init__.py b/basicswap/__init__.py index 17b966c..73f5c3b 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.0.1" +__version__ = "0.0.2" diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 2433c86..14d7067 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2319,11 +2319,23 @@ class BasicSwap(): def calltx(self, cmd): 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) - 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) out = p.communicate() if len(out[1]) > 0: raise ValueError('TX error ' + str(out[1])) 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() diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 80352b3..16d3c9a 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -126,6 +126,44 @@ class HttpHandler(BaseHTTPRequestHandler): def js_index(self, url_split): 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): swap_client = self.server.swap_client active_swaps = swap_client.listSwapsInProgress() @@ -141,9 +179,6 @@ class HttpHandler(BaseHTTPRequestHandler): def page_wallets(self, url_split, post_string): swap_client = self.server.swap_client - content = html_content_start(self.server.title, self.server.title) \ - + '
{% if refresh %}
Page Refresh: {{ refresh }} seconds
@@ -9,6 +7,9 @@ Page Refresh: {{ refresh }} seconds
Version: {{ version }}
+View Wallets
+RPC Console
+
Swaps in progress: {{ summary.num_swapping }}
Network Offers: {{ summary.num_network_offers }}
Sent Offers: {{ summary.num_sent_offers }}
diff --git a/basicswap/templates/offer_new.html b/basicswap/templates/offer_new.html
index 3f95738..503ec43 100644
--- a/basicswap/templates/offer_new.html
+++ b/basicswap/templates/offer_new.html
@@ -13,7 +13,7 @@
{% for c in coins %}
{% endfor %}
-'
+
{{ m }}
+{% endfor %} + + + +{% if result %} + +{% endif %} + + +