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) \ - + '

Wallets

' - messages = [] if 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) if url_split[1] == 'wallets': 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': return self.page_offer(url_split, post_string) if url_split[1] == 'offers': diff --git a/basicswap/templates/index.html b/basicswap/templates/index.html index 3f05048..6b0ee92 100644 --- a/basicswap/templates/index.html +++ b/basicswap/templates/index.html @@ -1,7 +1,5 @@ {% include 'header.html' %} -

View Wallets

-

{% 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 %} -' + Amount From Coin To @@ -21,7 +21,7 @@ {% for c in coins %} {% endfor %} -' + Amount To Contract locked (hrs)Participate txn will be locked for half the time. diff --git a/basicswap/templates/rpc.html b/basicswap/templates/rpc.html new file mode 100644 index 0000000..5f3ad69 --- /dev/null +++ b/basicswap/templates/rpc.html @@ -0,0 +1,28 @@ +{% include 'header.html' %} + +

New Offer

+{% for m in messages %} +

{{ m }}

+{% endfor %} + +
+

+
+
+ + +

+
+ +{% if result %} + +{% endif %} + +

home

+ \ No newline at end of file