diff --git a/basicswap/interface_xmr.py b/basicswap/interface_xmr.py index 4817bd0..eac7606 100644 --- a/basicswap/interface_xmr.py +++ b/basicswap/interface_xmr.py @@ -25,6 +25,7 @@ from .util import ( format_amount) from .rpc_xmr import ( make_xmr_rpc_func, + make_xmr_rpc2_func, make_xmr_wallet_rpc_func) from .ecc_util import ( b2i, i2b, b2h) @@ -56,11 +57,10 @@ class XMRInterface(CoinInterface): def __init__(self, coin_settings, network): super().__init__() - rpc_cb = make_xmr_rpc_func(coin_settings['rpcport'], host=coin_settings.get('rpchost', 'localhost')) - rpc_wallet_cb = make_xmr_wallet_rpc_func(coin_settings['walletrpcport'], coin_settings['walletrpcauth']) + self.rpc_cb = make_xmr_rpc_func(coin_settings['rpcport'], host=coin_settings.get('rpchost', 'localhost')) + self.rpc_cb2 = make_xmr_rpc2_func(coin_settings['rpcport'], host=coin_settings.get('rpchost', 'localhost')) # non-json endpoint + self.rpc_wallet_cb = make_xmr_wallet_rpc_func(coin_settings['walletrpcport'], coin_settings['walletrpcauth']) - self.rpc_cb = rpc_cb - self.rpc_wallet_cb = rpc_wallet_cb self._network = network self.blocks_confirmed = coin_settings['blocks_confirmed'] self._restore_height = coin_settings.get('restore_height', 0) @@ -107,12 +107,18 @@ class XMRInterface(CoinInterface): def getBlockchainInfo(self): rv = {} - rv['blocks'] = self.rpc_cb('get_block_count')['count'] + + # get_block_count returns "Internal error" if bootstrap-daemon is active + # rv['blocks'] = self.rpc_cb('get_block_count')['count'] + rv['blocks'] = self.rpc_cb2('get_height')['height'] rv['verificationprogress'] = 0 # TODO return rv def getChainHeight(self): - return self.rpc_cb('get_block_count')['count'] + # get_block_count returns "Internal error" if bootstrap-daemon is active + # return self.rpc_cb('get_info')['height'] + # return self.rpc_cb('get_block_count')['count'] + return self.rpc_cb2('get_height')['height'] def getWalletInfo(self): self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename}) @@ -243,7 +249,7 @@ class XMRInterface(CoinInterface): ''' # Debug try: - current_height = self.rpc_wallet_cb('get_block_count')['count'] + current_height = self.rpc_wallet_cb('get_height')['height'] logging.info('findTxB XMR current_height %d\nAddress: %s', current_height, address_b58) except Exception as e: logging.info('rpc_cb failed %s', str(e)) @@ -285,7 +291,7 @@ class XMRInterface(CoinInterface): num_tries = 40 for i in range(num_tries + 1): try: - current_height = self.rpc_cb('get_block_count')['count'] + current_height = self.rpc_cb2('get_height')['height'] print('current_height', current_height) except Exception as e: logging.warning('rpc_cb failed %s', str(e)) @@ -327,7 +333,7 @@ class XMRInterface(CoinInterface): self.rpc_wallet_cb('refresh') try: - current_height = self.rpc_cb('get_block_count')['count'] + current_height = self.rpc_cb2('get_height')['height'] logging.info('findTxnByHash XMR current_height %d\nhash: %s', current_height, txid) except Exception as e: logging.info('rpc_cb failed %s', str(e)) diff --git a/basicswap/rpc_xmr.py b/basicswap/rpc_xmr.py index 3742685..1d6b294 100644 --- a/basicswap/rpc_xmr.py +++ b/basicswap/rpc_xmr.py @@ -51,6 +51,23 @@ def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json return r['result'] +def callrpc_xmr2(rpc_port, method, params=None, rpc_host='127.0.0.1'): + try: + url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, method) + headers = { + 'content-type': 'application/json' + } + if params is None: + p = requests.post(url, headers=headers) + else: + p = requests.post(url, data=json.dumps(params), headers=headers) + r = json.loads(p.text) + except Exception as ex: + raise ValueError('RPC Server Error: {}'.format(str(ex))) + + return r + + def make_xmr_rpc_func(port, host='127.0.0.1'): port = port host = host @@ -62,6 +79,17 @@ def make_xmr_rpc_func(port, host='127.0.0.1'): return rpc_func +def make_xmr_rpc2_func(port, host='127.0.0.1'): + port = port + host = host + + def rpc_func(method, params=None, wallet=None): + nonlocal port + nonlocal host + return callrpc_xmr2(port, method, params, rpc_host=host) + return rpc_func + + def make_xmr_wallet_rpc_func(port, auth, host='127.0.0.1'): port = port auth = auth diff --git a/basicswap/templates/wallets.html b/basicswap/templates/wallets.html index 82de2e4..b59ee92 100644 --- a/basicswap/templates/wallets.html +++ b/basicswap/templates/wallets.html @@ -21,7 +21,7 @@ Blocks:{{ w.blocks }} Synced:{{ w.synced }} Expected Seed:{{ w.expected_seed }}{% if w.expected_seed != true %}{% endif %} -{{ w.deposit_address }} +{{ w.deposit_address }} Amount: Address: Subtract fee: Fee Rate:{{ w.fee_rate }}Est Fee:{{ w.est_fee }} diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index a8495df..ad1f703 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -292,6 +292,8 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic): fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport'])) fp.write('zmq-rpc-bind-ip=127.0.0.1\n') fp.write('prune-blockchain=1') + fp.write('restricted-rpc=1') + fp.write('bootstrap-daemon-address=auto') wallet_conf_path = os.path.join(data_dir, coin + '_wallet.conf') if os.path.exists(wallet_conf_path): diff --git a/doc/install.md b/doc/install.md index 2808e50..31361a6 100644 --- a/doc/install.md +++ b/doc/install.md @@ -83,7 +83,7 @@ Dependencies: $ wget -O coincurve-anonswap.zip https://github.com/tecnovert/coincurve/archive/anonswap.zip $ unzip coincurve-anonswap.zip $ cd $SWAP_DATADIR/coincurve-anonswap - $ python3 setup.py install --force + $ pip3 install . $ cd $SWAP_DATADIR @@ -106,6 +106,7 @@ Start the app $ basicswap-run --datadir=$SWAP_DATADIR Open in browser: `http://localhost:12700` +It may take a few minutes to start as the coin daemons are started before the http interface. Start after installed: