api: Fix offers path.

This commit is contained in:
tecnovert 2021-01-26 21:25:33 +02:00
parent c180f34f66
commit 7d0d0687cf
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
6 changed files with 59 additions and 8 deletions

View file

@ -29,6 +29,7 @@ from .interface_btc import BTCInterface
from .interface_ltc import LTCInterface
from .interface_nmc import NMCInterface
from .interface_xmr import XMRInterface
from .interface_bitcore_btc import BitcoreBTCInterface
from . import __version__
from .util import (
@ -600,6 +601,12 @@ class BasicSwap(BaseApp):
else:
raise ValueError('Unknown coin type')
def createBitcoreInterface(self, coin):
if coin == Coins.BTC:
return BitcoreBTCInterface(self.coin_clients[coin], self.chain)
else:
raise ValueError('Unknown coin type')
def setCoinRunParams(self, coin):
cc = self.coin_clients[coin]
if coin == Coins.XMR:
@ -636,6 +643,8 @@ class BasicSwap(BaseApp):
def createCoinInterface(self, coin):
if self.coin_clients[coin]['connection_type'] == 'rpc':
self.coin_clients[coin]['interface'] = self.createInterface(coin)
elif self.coin_clients[coin]['connection_type'] == 'bitcore':
self.coin_clients[coin]['interface'] = self.createBitcoreInterface(coin)
def start(self):
self.log.info('Starting BasicSwap %s, database v%d\n\n', __version__, self.db_version)

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
from .interface_btc import BTCInterface
from .contrib.test_framework.messages import (
CTxOut)
class BitcoreBTCInterface(BTCInterface):
def __init__(self, coin_settings, network):
super().__init__(coin_settings, network)
self.txoType = CTxOut
self._network = network
self.blocks_confirmed = coin_settings['blocks_confirmed']
self.setConfTarget(coin_settings['conf_target'])

View file

@ -31,7 +31,7 @@ from .rpc_xmr import (
make_xmr_rpc2_func,
make_xmr_wallet_rpc_func)
from .ecc_util import (
b2i, i2b, b2h)
b2i, b2h)
from .chainparams import CoinInterface, Coins
XMR_COIN = 10 ** 12

View file

@ -58,8 +58,8 @@ def js_offers(self, url_split, post_string, sent=False):
if post_string != '':
post_data = urllib.parse.parse_qs(post_string)
filters['coin_from'] = setCoinFilter(form_data, b'coin_from')
filters['coin_to'] = setCoinFilter(form_data, b'coin_to')
filters['coin_from'] = setCoinFilter(post_data, b'coin_from')
filters['coin_to'] = setCoinFilter(post_data, b'coin_to')
if b'sort_by' in post_data:
sort_by = post_data[b'sort_by'][0].decode('utf-8')

View file

@ -38,7 +38,7 @@ from basicswap.rpc_xmr import (
from basicswap.rpc import (
callrpc,
)
from tests.basicswap.mnemonics import mnemonics
from tests.basicswap.mnemonics import mnemonics as test_mnemonics
from tests.basicswap.common import (
waitForServer,
)
@ -68,7 +68,7 @@ UI_PORT = 12700 + PORT_OFS
BASE_PART_RPC_PORT = 19792
BASE_BTC_RPC_PORT = 19796
NUM_NODES = 3
NUM_NODES = int(os.getenv('NUM_NODES', 3))
EXTRA_CONFIG_JSON = json.loads(os.getenv('EXTRA_CONFIG_JSON', '{}'))
@ -78,6 +78,14 @@ if not len(logger.handlers):
logger.addHandler(logging.StreamHandler(sys.stdout))
def recursive_update_dict(base, new_vals):
for key, value in new_vals.items():
if key in base and isinstance(value, dict):
recursive_update_dict(base[key], value)
else:
base[key] = value
def callpartrpc(node_id, method, params=[], wallet=None, base_rpc_port=BASE_PART_RPC_PORT + PORT_OFS):
auth = 'test_part_{0}:test_part_pwd_{0}'.format(node_id)
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
@ -113,7 +121,9 @@ class Test(unittest.TestCase):
random.seed(time.time())
logging.info('Preparing %d nodes.', NUM_NODES)
for i in range(NUM_NODES):
logging.info('Preparing node: %d.', i)
client_path = os.path.join(test_path, 'client{}'.format(i))
config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
if RESET_TEST:
@ -133,11 +143,12 @@ class Test(unittest.TestCase):
'-datadir="{}"'.format(client_path),
'-bindir="{}"'.format(os.path.join(test_path, 'bin')),
'-portoffset={}'.format(i + PORT_OFS),
'-particl_mnemonic="{}"'.format(mnemonics[i]),
'-regtest',
'-withcoins=monero,bitcoin',
'-noextractover',
'-xmrrestoreheight=0']
if i < len(test_mnemonics):
testargs.append('-particl_mnemonic="{}"'.format(test_mnemonics[i]))
with patch.object(sys, 'argv', testargs):
prepareSystem.main()
@ -208,6 +219,9 @@ class Test(unittest.TestCase):
settings['chainclients']['bitcoin']['rpcuser'] = 'test_btc_' + str(i)
settings['chainclients']['bitcoin']['rpcpassword'] = 'test_btc_pwd_' + str(i)
extra_config = EXTRA_CONFIG_JSON.get('sc{}'.format(i), {})
recursive_update_dict(settings, extra_config)
with open(config_path, 'w') as fp:
json.dump(settings, fp, indent=4)
@ -230,8 +244,8 @@ class Test(unittest.TestCase):
self.processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
self.processes[-1].start()
waitForServer(self.delay_event, UI_PORT + 0)
waitForServer(self.delay_event, UI_PORT + 1)
for i in range(NUM_NODES):
waitForServer(self.delay_event, UI_PORT + i)
wallets = json.loads(urlopen('http://127.0.0.1:{}/json/wallets'.format(UI_PORT + 1)).read())

View file

@ -82,6 +82,15 @@ class Test(XmrTestBase):
assert(len(offers) == 1)
offer0 = offers[0]
post_data = {
'coin_from': '1'
}
test_post_offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers', data=parse.urlencode(post_data).encode()).read())
assert(len(test_post_offers) == 2)
post_data['coin_from'] = '2'
test_post_offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers', data=parse.urlencode(post_data).encode()).read())
assert(len(test_post_offers) == 0)
bid_data = {
'offer_id': offer0_id,
'amount_from': offer0['amount_from']}