started rpc page.
This commit is contained in:
		
							parent
							
								
									4972f1f60f
								
							
						
					
					
						commit
						cf73707643
					
				@ -1,3 +1,3 @@
 | 
			
		||||
name = "basicswap"
 | 
			
		||||
 | 
			
		||||
__version__ = "0.0.1"
 | 
			
		||||
__version__ = "0.0.2"
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
@ -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) \
 | 
			
		||||
            + '<h3>Wallets</h3>'
 | 
			
		||||
 | 
			
		||||
        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':
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,5 @@
 | 
			
		||||
{% include 'header.html' %}
 | 
			
		||||
 | 
			
		||||
<p><a href="/wallets">View Wallets</a></p>
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
{% if refresh %}
 | 
			
		||||
Page Refresh: {{ refresh }} seconds<br/>
 | 
			
		||||
@ -9,6 +7,9 @@ Page Refresh: {{ refresh }} seconds<br/>
 | 
			
		||||
Version: {{ version }}
 | 
			
		||||
</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="/offers">Network Offers: {{ summary.num_network_offers }}</a><br/>
 | 
			
		||||
<a href="/sentoffers">Sent Offers: {{ summary.num_sent_offers }}</a><br/>
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@
 | 
			
		||||
{% for c in coins %}
 | 
			
		||||
<option value="{{ c[0] }}">{{ c[1] }}</option>
 | 
			
		||||
{% endfor %}
 | 
			
		||||
</select>'
 | 
			
		||||
</select>
 | 
			
		||||
</td><td>Amount From</td><td><input type="text" name="amt_from"></td></tr>
 | 
			
		||||
 | 
			
		||||
<tr><td>Coin To</td><td>
 | 
			
		||||
@ -21,7 +21,7 @@
 | 
			
		||||
{% for c in coins %}
 | 
			
		||||
<option value="{{ c[0] }}">{{ c[1] }}</option>
 | 
			
		||||
{% endfor %}
 | 
			
		||||
</select>'
 | 
			
		||||
</select>
 | 
			
		||||
</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>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										28
									
								
								basicswap/templates/rpc.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								basicswap/templates/rpc.html
									
									
									
									
									
										Normal 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>
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user