api: Fix offers path.
This commit is contained in:
parent
c180f34f66
commit
7d0d0687cf
@ -29,6 +29,7 @@ from .interface_btc import BTCInterface
|
|||||||
from .interface_ltc import LTCInterface
|
from .interface_ltc import LTCInterface
|
||||||
from .interface_nmc import NMCInterface
|
from .interface_nmc import NMCInterface
|
||||||
from .interface_xmr import XMRInterface
|
from .interface_xmr import XMRInterface
|
||||||
|
from .interface_bitcore_btc import BitcoreBTCInterface
|
||||||
|
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from .util import (
|
from .util import (
|
||||||
@ -600,6 +601,12 @@ class BasicSwap(BaseApp):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Unknown coin type')
|
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):
|
def setCoinRunParams(self, coin):
|
||||||
cc = self.coin_clients[coin]
|
cc = self.coin_clients[coin]
|
||||||
if coin == Coins.XMR:
|
if coin == Coins.XMR:
|
||||||
@ -636,6 +643,8 @@ class BasicSwap(BaseApp):
|
|||||||
def createCoinInterface(self, coin):
|
def createCoinInterface(self, coin):
|
||||||
if self.coin_clients[coin]['connection_type'] == 'rpc':
|
if self.coin_clients[coin]['connection_type'] == 'rpc':
|
||||||
self.coin_clients[coin]['interface'] = self.createInterface(coin)
|
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):
|
def start(self):
|
||||||
self.log.info('Starting BasicSwap %s, database v%d\n\n', __version__, self.db_version)
|
self.log.info('Starting BasicSwap %s, database v%d\n\n', __version__, self.db_version)
|
||||||
|
19
basicswap/interface_bitcore_btc.py
Normal file
19
basicswap/interface_bitcore_btc.py
Normal 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'])
|
@ -31,7 +31,7 @@ from .rpc_xmr import (
|
|||||||
make_xmr_rpc2_func,
|
make_xmr_rpc2_func,
|
||||||
make_xmr_wallet_rpc_func)
|
make_xmr_wallet_rpc_func)
|
||||||
from .ecc_util import (
|
from .ecc_util import (
|
||||||
b2i, i2b, b2h)
|
b2i, b2h)
|
||||||
from .chainparams import CoinInterface, Coins
|
from .chainparams import CoinInterface, Coins
|
||||||
|
|
||||||
XMR_COIN = 10 ** 12
|
XMR_COIN = 10 ** 12
|
||||||
|
@ -58,8 +58,8 @@ def js_offers(self, url_split, post_string, sent=False):
|
|||||||
|
|
||||||
if post_string != '':
|
if post_string != '':
|
||||||
post_data = urllib.parse.parse_qs(post_string)
|
post_data = urllib.parse.parse_qs(post_string)
|
||||||
filters['coin_from'] = setCoinFilter(form_data, b'coin_from')
|
filters['coin_from'] = setCoinFilter(post_data, b'coin_from')
|
||||||
filters['coin_to'] = setCoinFilter(form_data, b'coin_to')
|
filters['coin_to'] = setCoinFilter(post_data, b'coin_to')
|
||||||
|
|
||||||
if b'sort_by' in post_data:
|
if b'sort_by' in post_data:
|
||||||
sort_by = post_data[b'sort_by'][0].decode('utf-8')
|
sort_by = post_data[b'sort_by'][0].decode('utf-8')
|
||||||
|
@ -38,7 +38,7 @@ from basicswap.rpc_xmr import (
|
|||||||
from basicswap.rpc import (
|
from basicswap.rpc import (
|
||||||
callrpc,
|
callrpc,
|
||||||
)
|
)
|
||||||
from tests.basicswap.mnemonics import mnemonics
|
from tests.basicswap.mnemonics import mnemonics as test_mnemonics
|
||||||
from tests.basicswap.common import (
|
from tests.basicswap.common import (
|
||||||
waitForServer,
|
waitForServer,
|
||||||
)
|
)
|
||||||
@ -68,7 +68,7 @@ UI_PORT = 12700 + PORT_OFS
|
|||||||
BASE_PART_RPC_PORT = 19792
|
BASE_PART_RPC_PORT = 19792
|
||||||
BASE_BTC_RPC_PORT = 19796
|
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', '{}'))
|
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))
|
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):
|
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)
|
auth = 'test_part_{0}:test_part_pwd_{0}'.format(node_id)
|
||||||
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
|
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
|
||||||
@ -113,7 +121,9 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
random.seed(time.time())
|
random.seed(time.time())
|
||||||
|
|
||||||
|
logging.info('Preparing %d nodes.', NUM_NODES)
|
||||||
for i in range(NUM_NODES):
|
for i in range(NUM_NODES):
|
||||||
|
logging.info('Preparing node: %d.', i)
|
||||||
client_path = os.path.join(test_path, 'client{}'.format(i))
|
client_path = os.path.join(test_path, 'client{}'.format(i))
|
||||||
config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
|
config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
|
||||||
if RESET_TEST:
|
if RESET_TEST:
|
||||||
@ -133,11 +143,12 @@ class Test(unittest.TestCase):
|
|||||||
'-datadir="{}"'.format(client_path),
|
'-datadir="{}"'.format(client_path),
|
||||||
'-bindir="{}"'.format(os.path.join(test_path, 'bin')),
|
'-bindir="{}"'.format(os.path.join(test_path, 'bin')),
|
||||||
'-portoffset={}'.format(i + PORT_OFS),
|
'-portoffset={}'.format(i + PORT_OFS),
|
||||||
'-particl_mnemonic="{}"'.format(mnemonics[i]),
|
|
||||||
'-regtest',
|
'-regtest',
|
||||||
'-withcoins=monero,bitcoin',
|
'-withcoins=monero,bitcoin',
|
||||||
'-noextractover',
|
'-noextractover',
|
||||||
'-xmrrestoreheight=0']
|
'-xmrrestoreheight=0']
|
||||||
|
if i < len(test_mnemonics):
|
||||||
|
testargs.append('-particl_mnemonic="{}"'.format(test_mnemonics[i]))
|
||||||
with patch.object(sys, 'argv', testargs):
|
with patch.object(sys, 'argv', testargs):
|
||||||
prepareSystem.main()
|
prepareSystem.main()
|
||||||
|
|
||||||
@ -208,6 +219,9 @@ class Test(unittest.TestCase):
|
|||||||
settings['chainclients']['bitcoin']['rpcuser'] = 'test_btc_' + str(i)
|
settings['chainclients']['bitcoin']['rpcuser'] = 'test_btc_' + str(i)
|
||||||
settings['chainclients']['bitcoin']['rpcpassword'] = 'test_btc_pwd_' + 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:
|
with open(config_path, 'w') as fp:
|
||||||
json.dump(settings, fp, indent=4)
|
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.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
|
||||||
self.processes[-1].start()
|
self.processes[-1].start()
|
||||||
|
|
||||||
waitForServer(self.delay_event, UI_PORT + 0)
|
for i in range(NUM_NODES):
|
||||||
waitForServer(self.delay_event, UI_PORT + 1)
|
waitForServer(self.delay_event, UI_PORT + i)
|
||||||
|
|
||||||
wallets = json.loads(urlopen('http://127.0.0.1:{}/json/wallets'.format(UI_PORT + 1)).read())
|
wallets = json.loads(urlopen('http://127.0.0.1:{}/json/wallets'.format(UI_PORT + 1)).read())
|
||||||
|
|
||||||
|
@ -82,6 +82,15 @@ class Test(XmrTestBase):
|
|||||||
assert(len(offers) == 1)
|
assert(len(offers) == 1)
|
||||||
offer0 = offers[0]
|
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 = {
|
bid_data = {
|
||||||
'offer_id': offer0_id,
|
'offer_id': offer0_id,
|
||||||
'amount_from': offer0['amount_from']}
|
'amount_from': offer0['amount_from']}
|
||||||
|
Loading…
Reference in New Issue
Block a user