api: Add wallet/createutxo

2024-05-20_merge
tecnovert 2 years ago
parent 59adf3368b
commit b43d58afbf
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 2
      basicswap/__init__.py
  2. 35
      basicswap/basicswap.py
  3. 6
      basicswap/chainparams.py
  4. 3
      basicswap/interface/dash.py
  5. 6
      basicswap/interface/firo.py
  6. 3
      basicswap/interface/pivx.py
  7. 108
      basicswap/js_server.py
  8. 4
      basicswap/templates/bid.html
  9. 4
      basicswap/templates/bid_xmr.html
  10. 26
      tests/basicswap/extended/test_dash.py
  11. 18
      tests/basicswap/extended/test_firo.py
  12. 2
      tests/basicswap/extended/test_nmc.py
  13. 26
      tests/basicswap/extended/test_pivx.py

@ -1,3 +1,3 @@
name = "basicswap" name = "basicswap"
__version__ = "0.11.48" __version__ = "0.11.49"

@ -6035,6 +6035,8 @@ class BasicSwap(BaseApp):
ci_to = self.ci(int(coin_to)) ci_to = self.ci(int(coin_to))
name_from = ci_from.chainparams()['name'] name_from = ci_from.chainparams()['name']
name_to = ci_to.chainparams()['name'] name_to = ci_to.chainparams()['name']
exchange_name_from = ci_from.getExchangeName('coingecko.com')
exchange_name_to = ci_to.getExchangeName('coingecko.com')
ticker_from = ci_from.chainparams()['ticker'] ticker_from = ci_from.chainparams()['ticker']
ticker_to = ci_to.chainparams()['ticker'] ticker_to = ci_to.chainparams()['ticker']
headers = {'Connection': 'close'} headers = {'Connection': 'close'}
@ -6044,23 +6046,42 @@ class BasicSwap(BaseApp):
if rate_sources.get('coingecko.com', True): if rate_sources.get('coingecko.com', True):
try: try:
url = 'https://api.coingecko.com/api/v3/simple/price?ids={},{}&vs_currencies=usd,btc'.format(name_from, name_to) url = 'https://api.coingecko.com/api/v3/simple/price?ids={},{}&vs_currencies=usd,btc'.format(exchange_name_from, exchange_name_to)
self.log.debug(f'lookupRates: {url}') self.log.debug(f'lookupRates: {url}')
start = time.time() start = time.time()
req = urllib.request.Request(url, headers=headers) req = urllib.request.Request(url, headers=headers)
js = json.loads(urllib.request.urlopen(req, timeout=10).read()) js = json.loads(urllib.request.urlopen(req, timeout=10).read())
js['time_taken'] = time.time() - start js['time_taken'] = time.time() - start
rate = float(js[name_from]['usd']) / float(js[name_to]['usd']) rate = float(js[exchange_name_from]['usd']) / float(js[exchange_name_to]['usd'])
js['rate_inferred'] = ci_to.format_amount(rate, conv_int=True, r=1) js['rate_inferred'] = ci_to.format_amount(rate, conv_int=True, r=1)
rv['coingecko'] = js rv['coingecko'] = js
except Exception as e: except Exception as e:
rv['coingecko_error'] = str(e) rv['coingecko_error'] = str(e)
if self.debug:
self.log.error(traceback.format_exc())
if exchange_name_from != name_from:
js[name_from] = js[exchange_name_from]
js.pop(exchange_name_from)
if exchange_name_to != name_to:
js[name_to] = js[exchange_name_to]
js.pop(exchange_name_to)
if rate_sources.get('bittrex.com', True): if rate_sources.get('bittrex.com', True):
bittrex_api_v3 = 'https://api.bittrex.com/v3' bittrex_api_v3 = 'https://api.bittrex.com/v3'
try: try:
exchange_ticker_to = ci_to.getExchangeTicker('bittrex.com')
exchange_ticker_from = ci_from.getExchangeTicker('bittrex.com')
USDT_coins = (Coins.FIRO,)
# TODO: How to compare USDT pairs with BTC pairs
if ci_from.coin_type() in USDT_coins:
raise ValueError('No BTC pair')
if ci_to.coin_type() in USDT_coins:
raise ValueError('No BTC pair')
if ci_from.coin_type() == Coins.BTC: if ci_from.coin_type() == Coins.BTC:
pair = f'{ticker_to}-{ticker_from}' pair = f'{exchange_ticker_to}-{exchange_ticker_from}'
url = f'{bittrex_api_v3}/markets/{pair}/ticker' url = f'{bittrex_api_v3}/markets/{pair}/ticker'
self.log.debug(f'lookupRates: {url}') self.log.debug(f'lookupRates: {url}')
start = time.time() start = time.time()
@ -6078,7 +6099,7 @@ class BasicSwap(BaseApp):
js['to_btc'] = js['lastTradeRate'] js['to_btc'] = js['lastTradeRate']
rv['bittrex'] = js rv['bittrex'] = js
elif ci_to.coin_type() == Coins.BTC: elif ci_to.coin_type() == Coins.BTC:
pair = f'{ticker_from}-{ticker_to}' pair = f'{exchange_ticker_from}-{exchange_ticker_to}'
url = f'{bittrex_api_v3}/markets/{pair}/ticker' url = f'{bittrex_api_v3}/markets/{pair}/ticker'
self.log.debug(f'lookupRates: {url}') self.log.debug(f'lookupRates: {url}')
start = time.time() start = time.time()
@ -6091,7 +6112,7 @@ class BasicSwap(BaseApp):
js['to_btc'] = 1.0 js['to_btc'] = 1.0
rv['bittrex'] = js rv['bittrex'] = js
else: else:
pair = f'{ticker_from}-BTC' pair = f'{exchange_ticker_from}-BTC'
url = f'{bittrex_api_v3}/markets/{pair}/ticker' url = f'{bittrex_api_v3}/markets/{pair}/ticker'
self.log.debug(f'lookupRates: {url}') self.log.debug(f'lookupRates: {url}')
start = time.time() start = time.time()
@ -6100,7 +6121,7 @@ class BasicSwap(BaseApp):
js_from['time_taken'] = time.time() - start js_from['time_taken'] = time.time() - start
js_from['pair'] = pair js_from['pair'] = pair
pair = f'{ticker_to}-BTC' pair = f'{exchange_ticker_to}-BTC'
url = f'{bittrex_api_v3}/markets/{pair}/ticker' url = f'{bittrex_api_v3}/markets/{pair}/ticker'
self.log.debug(f'lookupRates: {url}') self.log.debug(f'lookupRates: {url}')
start = time.time() start = time.time()
@ -6124,6 +6145,8 @@ class BasicSwap(BaseApp):
} }
except Exception as e: except Exception as e:
rv['bittrex_error'] = str(e) rv['bittrex_error'] = str(e)
if self.debug:
self.log.error(traceback.format_exc())
if output_array: if output_array:

@ -374,6 +374,12 @@ class CoinInterface:
ticker = 'rt' + ticker ticker = 'rt' + ticker
return ticker return ticker
def getExchangeTicker(self, exchange_name):
return self.ticker()
def getExchangeName(self, exchange_name):
return chainparams[self.coin_type()]['name']
def ticker_mainnet(self): def ticker_mainnet(self):
ticker = chainparams[self.coin_type()]['ticker'] ticker = chainparams[self.coin_type()]['ticker']
return ticker return ticker

@ -39,3 +39,6 @@ class DASHInterface(BTCInterface):
def withdrawCoin(self, value, addr_to, subfee): def withdrawCoin(self, value, addr_to, subfee):
params = [addr_to, value, '', '', subfee] params = [addr_to, value, '', '', subfee]
return self.rpc_callback('sendtoaddress', params) return self.rpc_callback('sendtoaddress', params)
def getSpendableBalance(self):
return self.make_int(self.rpc_callback('getwalletinfo')['balance'])

@ -30,6 +30,9 @@ class FIROInterface(BTCInterface):
def coin_type(): def coin_type():
return Coins.FIRO return Coins.FIRO
def getExchangeName(self, exchange_name):
return 'zcoin'
def initialiseWallet(self, key): def initialiseWallet(self, key):
# load with -hdseed= parameter # load with -hdseed= parameter
pass pass
@ -171,3 +174,6 @@ class FIROInterface(BTCInterface):
def getWalletSeedID(self): def getWalletSeedID(self):
return self.rpc_callback('getwalletinfo')['hdmasterkeyid'] return self.rpc_callback('getwalletinfo')['hdmasterkeyid']
def getSpendableBalance(self):
return self.make_int(self.rpc_callback('getwalletinfo')['balance'])

@ -62,3 +62,6 @@ class PIVXInterface(BTCInterface):
def withdrawCoin(self, value, addr_to, subfee): def withdrawCoin(self, value, addr_to, subfee):
params = [addr_to, value, '', '', subfee] params = [addr_to, value, '', '', subfee]
return self.rpc_callback('sendtoaddress', params) return self.rpc_callback('sendtoaddress', params)
def getSpendableBalance(self):
return self.make_int(self.rpc_callback('getwalletinfo')['balance'])

@ -37,17 +37,24 @@ from .ui.page_offers import postNewOffer
from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey
def getFormData(post_string, is_json):
if post_string == '':
raise ValueError('No post data')
if is_json:
form_data = json.loads(post_string)
form_data['is_json'] = True
else:
form_data = urllib.parse.parse_qs(post_string)
return form_data
def js_error(self, error_str): def js_error(self, error_str):
error_str_json = json.dumps({'error': error_str}) error_str_json = json.dumps({'error': error_str})
return bytes(error_str_json, 'UTF-8') return bytes(error_str_json, 'UTF-8')
def withdraw_coin(swap_client, coin_type, post_string, is_json): def withdraw_coin(swap_client, coin_type, post_string, is_json):
if is_json: post_data = getFormData(post_string, is_json)
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
value = get_data_entry(post_data, 'value') value = get_data_entry(post_data, 'value')
address = get_data_entry(post_data, 'address') address = get_data_entry(post_data, 'address')
@ -99,6 +106,13 @@ def js_wallets(self, url_split, post_string, is_json):
return bytes(json.dumps(withdraw_coin(swap_client, coin_type, post_string, is_json)), 'UTF-8') return bytes(json.dumps(withdraw_coin(swap_client, coin_type, post_string, is_json)), 'UTF-8')
if cmd == 'nextdepositaddr': if cmd == 'nextdepositaddr':
return bytes(json.dumps(swap_client.cacheNewAddressForCoin(coin_type)), 'UTF-8') return bytes(json.dumps(swap_client.cacheNewAddressForCoin(coin_type)), 'UTF-8')
if cmd == 'createutxo':
post_data = getFormData(post_string, is_json)
ci = swap_client.ci(coin_type)
value = ci.make_int(get_data_entry(post_data, 'value'))
txid_hex, new_addr = ci.createUTXO(value)
return bytes(json.dumps({'txid': txid_hex, 'address': new_addr}), 'UTF-8')
raise ValueError('Unknown command') raise ValueError('Unknown command')
rv = swap_client.getWalletInfo(coin_type) rv = swap_client.getWalletInfo(coin_type)
@ -113,13 +127,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
offer_id = None offer_id = None
if len(url_split) > 3: if len(url_split) > 3:
if url_split[3] == 'new': if url_split[3] == 'new':
if post_string == '': form_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
form_data = json.loads(post_string)
form_data['is_json'] = True
else:
form_data = urllib.parse.parse_qs(post_string)
offer_id = postNewOffer(swap_client, form_data) offer_id = postNewOffer(swap_client, form_data)
rv = {'offer_id': offer_id.hex()} rv = {'offer_id': offer_id.hex()}
return bytes(json.dumps(rv), 'UTF-8') return bytes(json.dumps(rv), 'UTF-8')
@ -138,11 +146,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
filters['offer_id'] = offer_id filters['offer_id'] = offer_id
if post_string != '': if post_string != '':
if is_json: post_data = getFormData(post_string, is_json)
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
filters['coin_from'] = setCoinFilter(post_data, 'coin_from') filters['coin_from'] = setCoinFilter(post_data, 'coin_from')
filters['coin_to'] = setCoinFilter(post_data, 'coin_to') filters['coin_to'] = setCoinFilter(post_data, 'coin_to')
@ -191,13 +195,7 @@ def js_bids(self, url_split, post_string, is_json):
swap_client.checkSystemStatus() swap_client.checkSystemStatus()
if len(url_split) > 3: if len(url_split) > 3:
if url_split[3] == 'new': if url_split[3] == 'new':
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id')) offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id'))
assert (len(offer_id) == 28) assert (len(offer_id) == 28)
@ -246,11 +244,7 @@ def js_bids(self, url_split, post_string, is_json):
show_txns = False show_txns = False
if post_string != '': if post_string != '':
if is_json: post_data = getFormData(post_string, is_json)
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
if have_data_entry(post_data, 'accept'): if have_data_entry(post_data, 'accept'):
swap_client.acceptBid(bid_id) swap_client.acceptBid(bid_id)
elif have_data_entry(post_data, 'debugind'): elif have_data_entry(post_data, 'debugind'):
@ -314,13 +308,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json):
swap_client = self.server.swap_client swap_client = self.server.swap_client
swap_client.checkSystemStatus() swap_client.checkSystemStatus()
if len(url_split) > 3: if len(url_split) > 3:
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
if url_split[3] == 'new': if url_split[3] == 'new':
addressnote = get_data_entry_or(post_data, 'addressnote', '') addressnote = get_data_entry_or(post_data, 'addressnote', '')
new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote) new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote)
@ -341,13 +329,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json):
def js_rates(self, url_split, post_string, is_json): def js_rates(self, url_split, post_string, is_json):
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
sc = self.server.swap_client sc = self.server.swap_client
coin_from = get_data_entry(post_data, 'coin_from') coin_from = get_data_entry(post_data, 'coin_from')
@ -365,13 +347,7 @@ def js_rates_list(self, url_split, query_string, is_json):
def js_rate(self, url_split, post_string, is_json): def js_rate(self, url_split, post_string, is_json):
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
sc = self.server.swap_client sc = self.server.swap_client
coin_from = getCoinType(get_data_entry(post_data, 'coin_from')) coin_from = getCoinType(get_data_entry(post_data, 'coin_from'))
@ -447,13 +423,7 @@ def js_vacuumdb(self, url_split, post_string, is_json):
def js_getcoinseed(self, url_split, post_string, is_json): def js_getcoinseed(self, url_split, post_string, is_json):
swap_client = self.server.swap_client swap_client = self.server.swap_client
swap_client.checkSystemStatus() swap_client.checkSystemStatus()
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
coin = getCoinType(get_data_entry(post_data, 'coin')) coin = getCoinType(get_data_entry(post_data, 'coin'))
if coin in (Coins.PART, Coins.PART_ANON, Coins.PART_BLIND): if coin in (Coins.PART, Coins.PART_ANON, Coins.PART_BLIND):
@ -471,13 +441,7 @@ def js_setpassword(self, url_split, post_string, is_json):
# Only works with currently enabled coins # Only works with currently enabled coins
# Will fail if any coin does not unlock on the old password # Will fail if any coin does not unlock on the old password
swap_client = self.server.swap_client swap_client = self.server.swap_client
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
old_password = get_data_entry(post_data, 'oldpassword') old_password = get_data_entry(post_data, 'oldpassword')
new_password = get_data_entry(post_data, 'newpassword') new_password = get_data_entry(post_data, 'newpassword')
@ -497,13 +461,7 @@ def js_setpassword(self, url_split, post_string, is_json):
def js_unlock(self, url_split, post_string, is_json): def js_unlock(self, url_split, post_string, is_json):
swap_client = self.server.swap_client swap_client = self.server.swap_client
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
password = get_data_entry(post_data, 'password') password = get_data_entry(post_data, 'password')
@ -520,13 +478,7 @@ def js_unlock(self, url_split, post_string, is_json):
def js_lock(self, url_split, post_string, is_json): def js_lock(self, url_split, post_string, is_json):
swap_client = self.server.swap_client swap_client = self.server.swap_client
if post_string == '': post_data = getFormData(post_string, is_json)
raise ValueError('No post data')
if is_json:
post_data = json.loads(post_string)
post_data['is_json'] = True
else:
post_data = urllib.parse.parse_qs(post_string)
if have_data_entry(post_data, 'coin'): if have_data_entry(post_data, 'coin'):
coin = getCoinType(get_data_entry(post_data, 'coin')) coin = getCoinType(get_data_entry(post_data, 'coin'))

@ -335,7 +335,7 @@
</div> </div>
<div class="w-full md:w-auto p-1.5"> <div class="w-full md:w-auto p-1.5">
<button name="edit_bid_submit" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"> <button name="edit_bid_submit" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Submit Edit Bid </button> <svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Submit Edit </button>
</div> </div>
{% else %} {% else %}
{% if data.show_bidder_seq_diagram %} {% if data.show_bidder_seq_diagram %}
@ -379,7 +379,7 @@
{% endif %} {% endif %}
<div class="w-full md:w-auto p-1.5"> <div class="w-full md:w-auto p-1.5">
<button name="edit_bid" type="submit" value="Edit Bid" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"> <button name="edit_bid" type="submit" value="Edit Bid" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Edit bit </button> <svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Edit bid </button>
</div> </div>
{% endif %} {% endif %}
{% if data.was_received == 'True' %} {% if data.was_received == 'True' %}

@ -493,7 +493,7 @@
</div> </div>
<div class="w-full md:w-auto p-1.5"> <div class="w-full md:w-auto p-1.5">
<button name="edit_bid_submit" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"> <button name="edit_bid_submit" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Submit Edit Bid </button> <svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Submit Edit </button>
</div> </div>
{% else %} {% else %}
{% if data.show_bidder_seq_diagram %} {% if data.show_bidder_seq_diagram %}
@ -537,7 +537,7 @@
{% endif %} {% endif %}
<div class="w-full md:w-auto p-1.5"> <div class="w-full md:w-auto p-1.5">
<button name="edit_bid" type="submit" value="Edit Bid" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"> <button name="edit_bid" type="submit" value="Edit Bid" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Edit bit </button> <svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Edit bid </button>
</div> </div>
{% endif %} {% endif %}
{% if data.was_received == 'True' %} {% if data.was_received == 'True' %}

@ -56,7 +56,6 @@ from tests.basicswap.common import (
wait_for_bid_tx_state, wait_for_bid_tx_state,
wait_for_in_progress, wait_for_in_progress,
read_json_api, read_json_api,
post_json_req,
TEST_HTTP_HOST, TEST_HTTP_HOST,
TEST_HTTP_PORT, TEST_HTTP_PORT,
BASE_PORT, BASE_PORT,
@ -247,6 +246,7 @@ def make_part_cli_rpc_func(node_id):
class Test(unittest.TestCase): class Test(unittest.TestCase):
test_coin_from = Coins.DASH
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
@ -273,7 +273,10 @@ class Test(unittest.TestCase):
btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE)) btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE))
if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')): if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')):
try:
callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet')
except Exception:
callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat create', 'bitcoin-wallet')
cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND))
logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid) logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid)
cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(DASH_NODE)), cfg.DASH_BINDIR, cfg.DASHD)) cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(DASH_NODE)), cfg.DASH_BINDIR, cfg.DASHD))
@ -282,7 +285,10 @@ class Test(unittest.TestCase):
for i in range(NUM_NODES): for i in range(NUM_NODES):
data_dir = os.path.join(cfg.TEST_DATADIRS, str(i)) data_dir = os.path.join(cfg.TEST_DATADIRS, str(i))
if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')):
try:
callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet')
except Exception:
callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'particl-wallet')
cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD))
logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid) logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid)
@ -334,7 +340,7 @@ class Test(unittest.TestCase):
logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr)
btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr))
ro = btcRpc('getdeploymentinfo') ro = btcRpc('getblockchaininfo')
checkForks(ro) checkForks(ro)
ro = dashRpc('getwalletinfo') ro = dashRpc('getwalletinfo')
@ -513,19 +519,27 @@ class Test(unittest.TestCase):
swap_clients[0].getChainClientSettings(Coins.DASH)['override_feerate'] = 10.0 swap_clients[0].getChainClientSettings(Coins.DASH)['override_feerate'] = 10.0
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60)
def test_08_withdrawal(self): def test_08_wallet(self):
logging.info('---------- Test DASH withdrawals') logging.info('---------- Test {} wallet'.format(self.test_coin_from.name))
logging.info('Test withdrawal')
addr = dashRpc('getnewaddress \"Withdrawal test\"') addr = dashRpc('getnewaddress \"Withdrawal test\"')
wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets')
assert (float(wallets['DASH']['balance']) > 100) assert (float(wallets[self.test_coin_from.name]['balance']) > 100)
post_json = { post_json = {
'value': 100, 'value': 100,
'address': addr, 'address': addr,
'subfee': False, 'subfee': False,
} }
json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/dash/withdraw'.format(TEST_HTTP_PORT + 0), post_json)) json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64)
logging.info('Test createutxo')
post_json = {
'value': 10,
}
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64) assert (len(json_rv['txid']) == 64)
def test_09_initialise_wallet(self): def test_09_initialise_wallet(self):

@ -6,7 +6,6 @@
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import os import os
import json
import random import random
import logging import logging
import unittest import unittest
@ -35,7 +34,6 @@ from tests.basicswap.common import (
wait_for_bid, wait_for_bid,
make_rpc_func, make_rpc_func,
read_json_api, read_json_api,
post_json_req,
TEST_HTTP_PORT, TEST_HTTP_PORT,
wait_for_offer, wait_for_offer,
wait_for_in_progress, wait_for_in_progress,
@ -105,9 +103,9 @@ def prepareDataDir(datadir, node_id, conf_file, dir_prefix, base_p2p_port, base_
class Test(BaseTest): class Test(BaseTest):
__test__ = True __test__ = True
test_coin_from = Coins.FIRO
firo_daemons = [] firo_daemons = []
firo_addr = None firo_addr = None
test_coin_from = Coins.FIRO
start_ltc_nodes = False start_ltc_nodes = False
start_xmr_nodes = False start_xmr_nodes = False
@ -397,9 +395,10 @@ class Test(BaseTest):
swap_clients[0].getChainClientSettings(Coins.FIRO)['override_feerate'] = 10.0 swap_clients[0].getChainClientSettings(Coins.FIRO)['override_feerate'] = 10.0
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60)
def test_08_withdrawal(self): def test_08_wallet(self):
logging.info('---------- Test {} withdrawals'.format(self.test_coin_from.name)) logging.info('---------- Test {} wallet'.format(self.test_coin_from.name))
logging.info('Test withdrawal')
addr = self.callnoderpc('getnewaddress', ['Withdrawal test', ]) addr = self.callnoderpc('getnewaddress', ['Withdrawal test', ])
wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets')
assert (float(wallets[self.test_coin_from.name]['balance']) > 100) assert (float(wallets[self.test_coin_from.name]['balance']) > 100)
@ -409,7 +408,14 @@ class Test(BaseTest):
'address': addr, 'address': addr,
'subfee': False, 'subfee': False,
} }
json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/{}/withdraw'.format(TEST_HTTP_PORT + 0, self.test_coin_from.name.lower()), post_json)) json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64)
logging.info('Test createutxo')
post_json = {
'value': 10,
}
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64) assert (len(json_rv['txid']) == 64)
def test_101_full_swap(self): def test_101_full_swap(self):

@ -332,7 +332,7 @@ class Test(unittest.TestCase):
logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr)
btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr))
ro = btcRpc('getdeploymentinfo') ro = btcRpc('getblockchaininfo')
checkForks(ro) checkForks(ro)
ro = nmcRpc('getwalletinfo') ro = nmcRpc('getwalletinfo')

@ -55,7 +55,6 @@ from tests.basicswap.common import (
wait_for_bid_tx_state, wait_for_bid_tx_state,
wait_for_in_progress, wait_for_in_progress,
read_json_api, read_json_api,
post_json_req,
TEST_HTTP_HOST, TEST_HTTP_HOST,
TEST_HTTP_PORT, TEST_HTTP_PORT,
BASE_PORT, BASE_PORT,
@ -252,6 +251,7 @@ def make_part_cli_rpc_func(node_id):
class Test(unittest.TestCase): class Test(unittest.TestCase):
test_coin_from = Coins.PIVX
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
@ -285,7 +285,10 @@ class Test(unittest.TestCase):
btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE)) btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE))
if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')): if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')):
try:
callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet')
except Exception:
callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat create', 'bitcoin-wallet')
cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND))
logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid) logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid)
cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(PIVX_NODE)), cfg.PIVX_BINDIR, cfg.PIVXD)) cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(PIVX_NODE)), cfg.PIVX_BINDIR, cfg.PIVXD))
@ -294,7 +297,10 @@ class Test(unittest.TestCase):
for i in range(NUM_NODES): for i in range(NUM_NODES):
data_dir = os.path.join(cfg.TEST_DATADIRS, str(i)) data_dir = os.path.join(cfg.TEST_DATADIRS, str(i))
if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')):
try:
callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet')
except Exception:
callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'particl-wallet')
cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD))
logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid) logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid)
@ -346,7 +352,7 @@ class Test(unittest.TestCase):
logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr)
btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr))
ro = btcRpc('getdeploymentinfo') ro = btcRpc('getblockchaininfo')
checkForks(ro) checkForks(ro)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
@ -522,19 +528,27 @@ class Test(unittest.TestCase):
swap_clients[0].getChainClientSettings(Coins.PIVX)['override_feerate'] = 10.0 swap_clients[0].getChainClientSettings(Coins.PIVX)['override_feerate'] = 10.0
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60)
def test_08_withdrawal(self): def test_08_wallet(self):
logging.info('---------- Test PIVX withdrawals') logging.info('---------- Test {} wallet'.format(self.test_coin_from.name))
logging.info('Test withdrawal')
addr = pivxRpc('getnewaddress \"Withdrawal test\"') addr = pivxRpc('getnewaddress \"Withdrawal test\"')
wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets')
assert (float(wallets['PIVX']['balance']) > 100) assert (float(wallets[self.test_coin_from.name]['balance']) > 100)
post_json = { post_json = {
'value': 100, 'value': 100,
'address': addr, 'address': addr,
'subfee': False, 'subfee': False,
} }
json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/pivx/withdraw'.format(TEST_HTTP_PORT + 0), post_json)) json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64)
logging.info('Test createutxo')
post_json = {
'value': 10,
}
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json)
assert (len(json_rv['txid']) == 64) assert (len(json_rv['txid']) == 64)
def test_09_v3_tx(self): def test_09_v3_tx(self):

Loading…
Cancel
Save