mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
scripts: Start example offer script.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
name = "basicswap"
|
||||
|
||||
__version__ = "0.11.56"
|
||||
__version__ = "0.11.57"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2022 tecnovert
|
||||
# Copyright (c) 2020-2023 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -49,11 +49,6 @@ def getFormData(post_string, is_json):
|
||||
return form_data
|
||||
|
||||
|
||||
def js_error(self, error_str):
|
||||
error_str_json = json.dumps({'error': error_str})
|
||||
return bytes(error_str_json, 'UTF-8')
|
||||
|
||||
|
||||
def withdraw_coin(swap_client, coin_type, post_string, is_json):
|
||||
post_data = getFormData(post_string, is_json)
|
||||
|
||||
@@ -73,17 +68,24 @@ def withdraw_coin(swap_client, coin_type, post_string, is_json):
|
||||
return {'txid': txid_hex}
|
||||
|
||||
|
||||
def js_coins(self, url_split, post_string, is_json):
|
||||
def js_error(self, error_str) -> bytes:
|
||||
error_str_json = json.dumps({'error': error_str})
|
||||
return bytes(error_str_json, 'UTF-8')
|
||||
|
||||
|
||||
def js_coins(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
|
||||
coins = []
|
||||
for coin in Coins:
|
||||
cc = swap_client.coin_clients[coin]
|
||||
coin_chainparams = chainparams[cc['coin']]
|
||||
entry = {
|
||||
'id': int(coin),
|
||||
'ticker': chainparams[cc['coin']]['ticker'],
|
||||
'ticker': coin_chainparams['ticker'],
|
||||
'name': getCoinName(coin),
|
||||
'active': False if cc['connection_type'] == 'none' else True,
|
||||
'decimal_places': coin_chainparams['decimal_places'],
|
||||
}
|
||||
if coin == Coins.PART_ANON:
|
||||
entry['variant'] = 'Anon'
|
||||
@@ -124,7 +126,7 @@ def js_wallets(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps(swap_client.getWalletsInfo({'ticker_key': True})), 'UTF-8')
|
||||
|
||||
|
||||
def js_offers(self, url_split, post_string, is_json, sent=False):
|
||||
def js_offers(self, url_split, post_string, is_json, sent=False) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
offer_id = None
|
||||
@@ -162,11 +164,13 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
|
||||
assert (sort_dir in ['asc', 'desc']), 'Invalid sort dir'
|
||||
filters['sort_dir'] = sort_dir
|
||||
|
||||
if b'offset' in post_data:
|
||||
if have_data_entry(post_data, 'offset'):
|
||||
filters['offset'] = int(get_data_entry(post_data, 'offset'))
|
||||
if b'limit' in post_data:
|
||||
if have_data_entry(post_data, 'limit'):
|
||||
filters['limit'] = int(get_data_entry(post_data, 'limit'))
|
||||
assert (filters['limit'] > 0 and filters['limit'] <= PAGE_LIMIT), 'Invalid limit'
|
||||
if have_data_entry(post_data, 'active'):
|
||||
filters['active'] = get_data_entry(post_data, 'active')
|
||||
|
||||
offers = swap_client.listOffers(sent, filters)
|
||||
rv = []
|
||||
@@ -190,11 +194,11 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
|
||||
return bytes(json.dumps(rv), 'UTF-8')
|
||||
|
||||
|
||||
def js_sentoffers(self, url_split, post_string, is_json):
|
||||
return self.js_offers(url_split, post_string, is_json, True)
|
||||
def js_sentoffers(self, url_split, post_string, is_json) -> bytes:
|
||||
return js_offers(self, url_split, post_string, is_json, True)
|
||||
|
||||
|
||||
def js_bids(self, url_split, post_string, is_json):
|
||||
def js_bids(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
if len(url_split) > 3:
|
||||
@@ -287,19 +291,19 @@ def js_bids(self, url_split, post_string, is_json):
|
||||
} for b in bids]), 'UTF-8')
|
||||
|
||||
|
||||
def js_sentbids(self, url_split, post_string, is_json):
|
||||
def js_sentbids(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
return bytes(json.dumps(swap_client.listBids(sent=True)), 'UTF-8')
|
||||
|
||||
|
||||
def js_network(self, url_split, post_string, is_json):
|
||||
def js_network(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
return bytes(json.dumps(swap_client.get_network_info()), 'UTF-8')
|
||||
|
||||
|
||||
def js_revokeoffer(self, url_split, post_string, is_json):
|
||||
def js_revokeoffer(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
offer_id = bytes.fromhex(url_split[3])
|
||||
@@ -308,7 +312,7 @@ def js_revokeoffer(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'revoked_offer': offer_id.hex()}), 'UTF-8')
|
||||
|
||||
|
||||
def js_smsgaddresses(self, url_split, post_string, is_json):
|
||||
def js_smsgaddresses(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
if len(url_split) > 3:
|
||||
@@ -332,7 +336,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps(swap_client.listAllSMSGAddresses()), 'UTF-8')
|
||||
|
||||
|
||||
def js_rates(self, url_split, post_string, is_json):
|
||||
def js_rates(self, url_split, post_string, is_json) -> bytes:
|
||||
post_data = getFormData(post_string, is_json)
|
||||
|
||||
sc = self.server.swap_client
|
||||
@@ -341,7 +345,7 @@ def js_rates(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps(sc.lookupRates(coin_from, coin_to)), 'UTF-8')
|
||||
|
||||
|
||||
def js_rates_list(self, url_split, query_string, is_json):
|
||||
def js_rates_list(self, url_split, query_string, is_json) -> bytes:
|
||||
get_data = urllib.parse.parse_qs(query_string)
|
||||
|
||||
sc = self.server.swap_client
|
||||
@@ -350,7 +354,7 @@ def js_rates_list(self, url_split, query_string, is_json):
|
||||
return bytes(json.dumps(sc.lookupRates(coin_from, coin_to, True)), 'UTF-8')
|
||||
|
||||
|
||||
def js_rate(self, url_split, post_string, is_json):
|
||||
def js_rate(self, url_split, post_string, is_json) -> bytes:
|
||||
post_data = getFormData(post_string, is_json)
|
||||
|
||||
sc = self.server.swap_client
|
||||
@@ -383,13 +387,13 @@ def js_rate(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'rate': rate}), 'UTF-8')
|
||||
|
||||
|
||||
def js_index(self, url_split, post_string, is_json):
|
||||
def js_index(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
return bytes(json.dumps(swap_client.getSummary()), 'UTF-8')
|
||||
|
||||
|
||||
def js_generatenotification(self, url_split, post_string, is_json):
|
||||
def js_generatenotification(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
|
||||
if not swap_client.debug:
|
||||
@@ -408,7 +412,7 @@ def js_generatenotification(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'type': r}), 'UTF-8')
|
||||
|
||||
|
||||
def js_notifications(self, url_split, post_string, is_json):
|
||||
def js_notifications(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
swap_client.getNotifications()
|
||||
@@ -416,7 +420,7 @@ def js_notifications(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps(swap_client.getNotifications()), 'UTF-8')
|
||||
|
||||
|
||||
def js_vacuumdb(self, url_split, post_string, is_json):
|
||||
def js_vacuumdb(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
swap_client.vacuumDB()
|
||||
@@ -424,7 +428,7 @@ def js_vacuumdb(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'completed': True}), 'UTF-8')
|
||||
|
||||
|
||||
def js_getcoinseed(self, url_split, post_string, is_json):
|
||||
def js_getcoinseed(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
post_data = getFormData(post_string, is_json)
|
||||
@@ -440,7 +444,7 @@ def js_getcoinseed(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'coin': ci.ticker(), 'seed': seed.hex()}), 'UTF-8')
|
||||
|
||||
|
||||
def js_setpassword(self, url_split, post_string, is_json):
|
||||
def js_setpassword(self, url_split, post_string, is_json) -> bytes:
|
||||
# Set or change wallet passwords
|
||||
# Only works with currently enabled coins
|
||||
# Will fail if any coin does not unlock on the old password
|
||||
@@ -463,7 +467,7 @@ def js_setpassword(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'success': True}), 'UTF-8')
|
||||
|
||||
|
||||
def js_unlock(self, url_split, post_string, is_json):
|
||||
def js_unlock(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
post_data = getFormData(post_string, is_json)
|
||||
|
||||
@@ -480,7 +484,7 @@ def js_unlock(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'success': True}), 'UTF-8')
|
||||
|
||||
|
||||
def js_lock(self, url_split, post_string, is_json):
|
||||
def js_lock(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
post_data = {} if post_string == '' else getFormData(post_string, is_json)
|
||||
|
||||
@@ -495,11 +499,11 @@ def js_lock(self, url_split, post_string, is_json):
|
||||
return bytes(json.dumps({'success': True}), 'UTF-8')
|
||||
|
||||
|
||||
def js_404(self, url_split, post_string, is_json):
|
||||
def js_404(self, url_split, post_string, is_json) -> bytes:
|
||||
return bytes(json.dumps({'Error': 'path unknown'}), 'UTF-8')
|
||||
|
||||
|
||||
def js_help(self, url_split, post_string, is_json):
|
||||
def js_help(self, url_split, post_string, is_json) -> bytes:
|
||||
# TODO: Add details and examples
|
||||
commands = []
|
||||
for k in pages:
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
<td class="bold">{{ data.amt_from }} {{ data.tla_from }}</td>
|
||||
</tr>
|
||||
<tr class="bg-white border-t hover:bg-gray-50">
|
||||
<td class="py-4 px-6 bold">Amount Bidder Send</td>
|
||||
<td class="py-4 px-6 bold">Amount Bidder Sends</td>
|
||||
<td class="bold">{{ data.amt_to }} {{ data.tla_to }}</td>
|
||||
</tr>
|
||||
<tr class="bg-white border-t hover:bg-gray-50">
|
||||
|
||||
@@ -58,9 +58,9 @@ def decode_offer_id(v):
|
||||
|
||||
|
||||
def swap_type_from_string(str_swap_type: str) -> SwapTypes:
|
||||
if str_swap_type == 'seller_first':
|
||||
if str_swap_type == 'seller_first' or str_swap_type == 'secret_hash':
|
||||
return SwapTypes.SELLER_FIRST
|
||||
elif str_swap_type == 'xmr_swap':
|
||||
elif str_swap_type == 'xmr_swap' or str_swap_type == 'adaptor_sig':
|
||||
return SwapTypes.XMR_SWAP
|
||||
else:
|
||||
raise ValueError('Unknown swap type')
|
||||
@@ -123,11 +123,15 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
||||
except Exception:
|
||||
errors.append('Minimum Bid Amount')
|
||||
|
||||
try:
|
||||
page_data['amt_to'] = get_data_entry(form_data, 'amt_to')
|
||||
parsed_data['amt_to'] = inputAmount(page_data['amt_to'], ci_to)
|
||||
except Exception:
|
||||
errors.append('Amount To')
|
||||
if (have_data_entry(form_data, 'rate')):
|
||||
parsed_data['rate'] = ci_to.make_int(form_data['rate'], r=1)
|
||||
page_data['rate'] = ci_to.format_amount(parsed_data['rate'])
|
||||
else:
|
||||
try:
|
||||
page_data['amt_to'] = get_data_entry(form_data, 'amt_to')
|
||||
parsed_data['amt_to'] = inputAmount(page_data['amt_to'], ci_to)
|
||||
except Exception:
|
||||
errors.append('Amount To')
|
||||
|
||||
if 'amt_to' in parsed_data and 'amt_from' in parsed_data:
|
||||
parsed_data['rate'] = ci_from.make_int(parsed_data['amt_to'] / parsed_data['amt_from'], r=1)
|
||||
@@ -141,19 +145,24 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
||||
page_data['automation_strat_id'] = int(get_data_entry_or(form_data, 'automation_strat_id', -1))
|
||||
parsed_data['automation_strat_id'] = page_data['automation_strat_id']
|
||||
swap_type = -1
|
||||
|
||||
if have_data_entry(form_data, 'subfee'):
|
||||
parsed_data['subfee'] = True
|
||||
if have_data_entry(form_data, 'swap_type'):
|
||||
page_data['swap_type'] = get_data_entry(form_data, 'swap_type')
|
||||
parsed_data['swap_type'] = page_data['swap_type']
|
||||
swap_type = swap_type_from_string(parsed_data['swap_type'])
|
||||
if have_data_entry(form_data, 'subfee'):
|
||||
parsed_data['subfee'] = True
|
||||
|
||||
if parsed_data['coin_to'] in (Coins.XMR, Coins.PART_ANON) or swap_type == SwapTypes.XMR_SWAP:
|
||||
page_data['swap_style'] = 'xmr'
|
||||
elif parsed_data['coin_to'] in (Coins.XMR, Coins.PART_ANON):
|
||||
parsed_data['swap_type'] = strSwapType(SwapTypes.XMR_SWAP)
|
||||
swap_type = SwapTypes.XMR_SWAP
|
||||
else:
|
||||
parsed_data['swap_type'] = strSwapType(SwapTypes.SELLER_FIRST)
|
||||
swap_type = SwapTypes.SELLER_FIRST
|
||||
|
||||
if swap_type == SwapTypes.XMR_SWAP:
|
||||
page_data['swap_style'] = 'xmr'
|
||||
else:
|
||||
page_data['swap_style'] = 'atomic'
|
||||
parsed_data['swap_type'] = strSwapType(SwapTypes.SELLER_FIRST)
|
||||
|
||||
if 'swap_type' in parsed_data:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user