ui: Add json endpoint to list all coin types.

2024-05-20_merge
tecnovert 2 years ago
parent 8b09607083
commit 18a444b071
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 4
      basicswap/http_server.py
  2. 22
      basicswap/js_server.py
  3. 12
      tests/basicswap/test_run.py

@ -33,6 +33,7 @@ from .basicswap_util import (
strAddressType, strAddressType,
) )
from .js_server import ( from .js_server import (
js_coins,
js_error, js_error,
js_wallets, js_wallets,
js_offers, js_offers,
@ -678,7 +679,8 @@ class HttpHandler(BaseHTTPRequestHandler):
self.putHeaders(status_code, 'text/plain') self.putHeaders(status_code, 'text/plain')
func = js_index func = js_index
if len(url_split) > 2: if len(url_split) > 2:
func = {'wallets': js_wallets, func = {'coins': js_coins,
'wallets': js_wallets,
'offers': js_offers, 'offers': js_offers,
'sentoffers': js_sentoffers, 'sentoffers': js_sentoffers,
'bids': js_bids, 'bids': js_bids,

@ -16,6 +16,7 @@ from .basicswap_util import (
) )
from .chainparams import ( from .chainparams import (
Coins, Coins,
chainparams,
) )
from .ui.util import ( from .ui.util import (
PAGE_LIMIT, PAGE_LIMIT,
@ -61,6 +62,27 @@ def withdraw_coin(swap_client, coin_type, post_string, is_json):
return {'txid': txid_hex} return {'txid': txid_hex}
def js_coins(self, url_split, post_string, is_json):
swap_client = self.server.swap_client
coins = []
for coin in Coins:
cc = swap_client.coin_clients[coin]
entry = {
'id': int(coin),
'ticker': chainparams[cc['coin']]['ticker'],
'name': cc['name'].capitalize(),
'active': False if cc['connection_type'] == 'none' else True,
}
if coin == Coins.PART_ANON:
entry['variant'] = 'Anon'
elif coin == Coins.PART_BLIND:
entry['variant'] = 'Blind'
coins.append(entry)
return bytes(json.dumps(coins), 'UTF-8')
def js_wallets(self, url_split, post_string, is_json): def js_wallets(self, url_split, post_string, is_json):
swap_client = self.server.swap_client swap_client = self.server.swap_client
if len(url_split) > 3: if len(url_split) > 3:

@ -85,6 +85,18 @@ class Test(BaseTest):
ci = self.swap_clients[0].ci(coin_type) ci = self.swap_clients[0].ci(coin_type)
return ci.make_int(float(js_wallets[str(int(coin_type))]['balance']) + float(js_wallets[str(int(coin_type))]['unconfirmed'])) return ci.make_int(float(js_wallets[str(int(coin_type))]['balance']) + float(js_wallets[str(int(coin_type))]['unconfirmed']))
def test_001_js_coins(self):
js_coins = read_json_api(1800, 'coins')
for c in Coins:
coin = next((x for x in js_coins if x['id'] == int(c)), None)
if c in (Coins.PART, Coins.BTC, Coins.LTC, Coins.PART_ANON, Coins.PART_BLIND):
assert(coin['active'] is True)
else:
assert(coin['active'] is False)
if c in (Coins.PART_ANON, Coins.PART_BLIND):
assert(coin['ticker'] == 'PART')
def test_01_verifyrawtransaction(self): def test_01_verifyrawtransaction(self):
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000' txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
prevout = { prevout = {

Loading…
Cancel
Save