ui: Improve rpc page.
This commit is contained in:
		
							parent
							
								
									62aa1fa5d7
								
							
						
					
					
						commit
						57bc1d5ccf
					
				@ -268,6 +268,7 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
 | 
			
		||||
        result = None
 | 
			
		||||
        cmd = ''
 | 
			
		||||
        coin_type_selected = -1
 | 
			
		||||
        coin_type = -1
 | 
			
		||||
        coin_id = -1
 | 
			
		||||
        call_type = 'cli'
 | 
			
		||||
@ -280,15 +281,10 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
                call_type = get_data_entry_or(form_data, 'call_type', 'cli')
 | 
			
		||||
                type_map = get_data_entry_or(form_data, 'type_map', '')
 | 
			
		||||
                try:
 | 
			
		||||
                    coin_id = int(get_data_entry(form_data, 'coin_type'))
 | 
			
		||||
                    if coin_id in (-2, -3, -4):
 | 
			
		||||
                        coin_type = Coins(Coins.XMR)
 | 
			
		||||
                    elif coin_id in (-5,):
 | 
			
		||||
                        coin_type = Coins(Coins.LTC)
 | 
			
		||||
                    elif coin_id in (-6,):
 | 
			
		||||
                        coin_type = Coins(Coins.DCR)
 | 
			
		||||
                    else:
 | 
			
		||||
                        coin_type = Coins(coin_id)
 | 
			
		||||
                    coin_type_selected = get_data_entry(form_data, 'coin_type')
 | 
			
		||||
                    coin_type_split = coin_type_selected.split(',')
 | 
			
		||||
                    coin_type = Coins(int(coin_type_split[0]))
 | 
			
		||||
                    coin_variant = int(coin_type_split[1])
 | 
			
		||||
                except Exception:
 | 
			
		||||
                    raise ValueError('Unknown Coin Type')
 | 
			
		||||
 | 
			
		||||
@ -299,29 +295,29 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
                    cmd = get_data_entry(form_data, 'cmd')
 | 
			
		||||
                except Exception:
 | 
			
		||||
                    raise ValueError('Invalid command')
 | 
			
		||||
                if coin_type == Coins.XMR:
 | 
			
		||||
                if coin_type in (Coins.XMR, ):
 | 
			
		||||
                    ci = swap_client.ci(coin_type)
 | 
			
		||||
                    arr = cmd.split(None, 1)
 | 
			
		||||
                    method = arr[0]
 | 
			
		||||
                    params = json.loads(arr[1]) if len(arr) > 1 else []
 | 
			
		||||
                    if coin_id == -4:
 | 
			
		||||
                    if coin_variant == 2:
 | 
			
		||||
                        rv = ci.rpc_wallet(method, params)
 | 
			
		||||
                    elif coin_id == -3:
 | 
			
		||||
                    elif coin_variant == 0:
 | 
			
		||||
                        rv = ci.rpc(method, params)
 | 
			
		||||
                    elif coin_id == -2:
 | 
			
		||||
                    elif coin_variant == 1:
 | 
			
		||||
                        if params == []:
 | 
			
		||||
                            params = None
 | 
			
		||||
                        rv = ci.rpc2(method, params)
 | 
			
		||||
                    else:
 | 
			
		||||
                        raise ValueError('Unknown XMR RPC variant')
 | 
			
		||||
                        raise ValueError('Unknown RPC variant')
 | 
			
		||||
                    result = json.dumps(rv, indent=4)
 | 
			
		||||
                else:
 | 
			
		||||
                    if call_type == 'http':
 | 
			
		||||
                        ci = swap_client.ci(coin_type)
 | 
			
		||||
                        method, params = parse_cmd(cmd, type_map)
 | 
			
		||||
                        if coin_id == -6:
 | 
			
		||||
                        if coin_variant == 1:
 | 
			
		||||
                            rv = ci.rpc_wallet(method, params)
 | 
			
		||||
                        elif coin_id == -5:
 | 
			
		||||
                        elif coin_variant == 2:
 | 
			
		||||
                            rv = ci.rpc_wallet_mweb(method, params)
 | 
			
		||||
                        else:
 | 
			
		||||
                            if coin_type in (Coins.DCR, ):
 | 
			
		||||
@ -340,24 +336,24 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
 | 
			
		||||
        template = env.get_template('rpc.html')
 | 
			
		||||
 | 
			
		||||
        coins = listAvailableCoins(swap_client, with_variants=False)
 | 
			
		||||
        with_xmr: bool = any(c[0] == Coins.XMR for c in coins)
 | 
			
		||||
        coins = [c for c in coins if c[0] != Coins.XMR]
 | 
			
		||||
        coin_available = listAvailableCoins(swap_client, with_variants=False)
 | 
			
		||||
        with_xmr: bool = any(c[0] == Coins.XMR for c in coin_available)
 | 
			
		||||
        coins = [(str(c[0]) + ',0', c[1]) for c in coin_available if c[0] not in (Coins.XMR, )]
 | 
			
		||||
 | 
			
		||||
        if any(c[0] == Coins.DCR for c in coins):
 | 
			
		||||
            coins.append((-6, 'Decred Wallet'))
 | 
			
		||||
        if any(c[0] == Coins.LTC for c in coins):
 | 
			
		||||
            coins.append((-5, 'Litecoin MWEB Wallet'))
 | 
			
		||||
        if any(c[0] == Coins.DCR for c in coin_available):
 | 
			
		||||
            coins.append((str(int(Coins.DCR)) + ',1', 'Decred Wallet'))
 | 
			
		||||
        if any(c[0] == Coins.LTC for c in coin_available):
 | 
			
		||||
            coins.append((str(int(Coins.LTC)) + ',2', 'Litecoin MWEB Wallet'))
 | 
			
		||||
        if with_xmr:
 | 
			
		||||
            coins.append((-2, 'Monero'))
 | 
			
		||||
            coins.append((-3, 'Monero JSON'))
 | 
			
		||||
            coins.append((-4, 'Monero Wallet'))
 | 
			
		||||
            coins.append((str(int(Coins.XMR)) + ',0', 'Monero'))
 | 
			
		||||
            coins.append((str(int(Coins.XMR)) + ',1', 'Monero JSON'))
 | 
			
		||||
            coins.append((str(int(Coins.XMR)) + ',2', 'Monero Wallet'))
 | 
			
		||||
 | 
			
		||||
        return self.render_template(template, {
 | 
			
		||||
            'messages': messages,
 | 
			
		||||
            'err_messages': err_messages,
 | 
			
		||||
            'coins': coins,
 | 
			
		||||
            'coin_type': coin_id,
 | 
			
		||||
            'coin_type': coin_type_selected,
 | 
			
		||||
            'call_type': call_type,
 | 
			
		||||
            'result': result,
 | 
			
		||||
            'messages': messages,
 | 
			
		||||
 | 
			
		||||
@ -178,7 +178,7 @@
 | 
			
		||||
</body>
 | 
			
		||||
<script>
 | 
			
		||||
    function set_method() {
 | 
			
		||||
        const coin_type = document.getElementById('coin_type').value;
 | 
			
		||||
        const coin_type = document.getElementById('coin_type').value.split(',')[0];
 | 
			
		||||
        if (coin_type == 4 || coin_type == -6) {
 | 
			
		||||
            const cmd = document.getElementById('cmd');
 | 
			
		||||
            const type_map = document.getElementById('type_map');
 | 
			
		||||
@ -189,9 +189,9 @@
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    function set_coin() {
 | 
			
		||||
        const coin_type = document.getElementById('coin_type').value;
 | 
			
		||||
        const coin_type = document.getElementById('coin_type').value.split(',')[0];
 | 
			
		||||
        let call_type = document.getElementById('call_type');
 | 
			
		||||
        if (coin_type == 4 || coin_type == -6) {
 | 
			
		||||
        if (coin_type == '4' || coin_type == '6') {
 | 
			
		||||
            call_type.disabled = true;
 | 
			
		||||
            call_type.value = 'http';
 | 
			
		||||
        } else {
 | 
			
		||||
@ -199,5 +199,8 @@
 | 
			
		||||
        }
 | 
			
		||||
        set_method();
 | 
			
		||||
    }
 | 
			
		||||
    document.addEventListener('DOMContentLoaded', () => {
 | 
			
		||||
        set_coin();
 | 
			
		||||
    });
 | 
			
		||||
  </script>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
@ -964,9 +964,7 @@
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
</script>
 | 
			
		||||
{% include 'footer.html' %}
 | 
			
		||||
<script>
 | 
			
		||||
 | 
			
		||||
  function confirmReseed() {
 | 
			
		||||
   return confirm("Are you sure?\nBackup your wallet before and after.\nWon't detect used keys.\nShould only be used for new wallets.");
 | 
			
		||||
  }
 | 
			
		||||
@ -979,5 +977,6 @@
 | 
			
		||||
   return confirm("Are you sure?");
 | 
			
		||||
  }
 | 
			
		||||
</script>
 | 
			
		||||
{% include 'footer.html' %}
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@ -63,7 +63,6 @@ logger = logging.getLogger()
 | 
			
		||||
DCR_BINDIR = os.path.expanduser(os.getenv('DCR_BINDIR', os.path.join(cfg.DEFAULT_TEST_BINDIR, 'decred')))
 | 
			
		||||
DCRD = os.getenv('DCRD', 'dcrd' + cfg.bin_suffix)
 | 
			
		||||
DCR_WALLET = os.getenv('DCR_WALLET', 'dcrwallet' + cfg.bin_suffix)
 | 
			
		||||
DCR_CLI = os.getenv('DCR_CLI', 'dcrctl' + cfg.bin_suffix)
 | 
			
		||||
 | 
			
		||||
DCR_BASE_PORT = 44932
 | 
			
		||||
DCR_BASE_RPC_PORT = 45932
 | 
			
		||||
@ -583,6 +582,10 @@ class Test(BaseTest):
 | 
			
		||||
 | 
			
		||||
        waitForRPC(make_rpc_func(i, base_rpc_port=DCR_BASE_WALLET_RPC_PORT), test_delay_event, rpc_command='getinfo', max_tries=12)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def addPIDInfo(cls, sc, i):
 | 
			
		||||
        sc.setDaemonPID(Coins.DCR, cls.dcr_daemons[i].handle.pid)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def addCoinSettings(cls, settings, datadir, node_id):
 | 
			
		||||
        settings['chainclients']['decred'] = {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user