ui: Show bids that can be accepted.

This commit is contained in:
tecnovert 2022-06-15 00:25:17 +02:00
parent 0edcf249aa
commit 3ed6eca95f
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
8 changed files with 78 additions and 27 deletions

View file

@ -5210,21 +5210,24 @@ class BasicSwap(BaseApp):
continue
num_watched_outputs += len(v['watched_outputs'])
bids_sent = 0
bids_received = 0
q = self.engine.execute('SELECT was_sent, was_received, COUNT(*) FROM bids GROUP BY was_sent, was_received ')
for r in q:
if r[0]:
bids_sent += r[2]
if r[1]:
bids_received += r[2]
now = int(time.time())
q = self.engine.execute('SELECT COUNT(*) FROM offers WHERE active_ind = 1 AND expire_at > {}'.format(now)).first()
num_offers = q[0]
q_str = '''SELECT
COUNT(CASE WHEN was_sent THEN 1 ELSE NULL END) AS count_sent,
COUNT(CASE WHEN was_received THEN 1 ELSE NULL END) AS count_received,
COUNT(CASE WHEN was_received AND state = {} AND expire_at > {} THEN 1 ELSE NULL END) AS count_available
FROM bids WHERE active_ind = 1'''.format(BidStates.BID_RECEIVED, now)
q = self.engine.execute(q_str).first()
bids_sent = q[0]
bids_received = q[1]
bids_available = q[2]
q = self.engine.execute('SELECT COUNT(*) FROM offers WHERE was_sent = 1').first()
num_sent_offers = q[0]
q_str = '''SELECT
COUNT(CASE WHEN expire_at > {} THEN 1 ELSE NULL END) AS count_active,
COUNT(CASE WHEN was_sent THEN 1 ELSE NULL END) AS count_sent
FROM offers WHERE active_ind = 1'''.format(now)
q = self.engine.execute(q_str).first()
num_offers = q[0]
num_sent_offers = q[1]
rv = {
'network': self.chain,
@ -5233,6 +5236,7 @@ class BasicSwap(BaseApp):
'num_sent_offers': num_sent_offers,
'num_recv_bids': bids_received,
'num_sent_bids': bids_sent,
'num_available_bids': bids_available,
'num_watched_outputs': num_watched_outputs,
}
return rv
@ -5455,6 +5459,13 @@ class BasicSwap(BaseApp):
else:
query_str += 'AND bids.was_received = 1 '
bid_state_ind = filters.get('bid_state_ind', -1)
if bid_state_ind != -1:
query_str += 'AND bids.state = {} '.format(bid_state_ind)
with_expired = filters.get('with_expired', True)
if with_expired is not True:
query_str += 'AND bids.expire_at > {} '.format(now)
sort_dir = filters.get('sort_dir', 'DESC').upper()
sort_by = filters.get('sort_by', 'created_at')
query_str += f' ORDER BY bids.{sort_by} {sort_dir}'

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 tecnovert
# Copyright (c) 2021-2022 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.

View file

@ -18,6 +18,7 @@ from . import __version__
from .util import (
dumpj,
ensure,
toBool,
format_timestamp,
)
from .chainparams import (
@ -26,6 +27,7 @@ from .chainparams import (
getCoinIdFromTicker,
)
from .basicswap_util import (
BidStates,
SwapTypes,
DebugTypes,
strBidState,
@ -50,6 +52,7 @@ from .ui.util import (
PAGE_LIMIT,
describeBid,
getCoinName,
listBidStates,
get_data_entry,
have_data_entry,
get_data_entry_or,
@ -716,15 +719,21 @@ class HttpHandler(BaseHTTPRequestHandler):
old_states=old_states,
), 'UTF-8')
def page_bids(self, url_split, post_string, sent=False):
def page_bids(self, url_split, post_string, sent=False, available=False):
swap_client = self.server.swap_client
filters = {
'page_no': 1,
'bid_state_ind': -1,
'with_expired': True,
'limit': PAGE_LIMIT,
'sort_by': 'created_at',
'sort_dir': 'desc',
}
if available:
filters['bid_state_ind'] = BidStates.BID_RECEIVED
filters['with_expired'] = False
messages = []
form_data = self.checkForm(post_string, 'bids', messages)
if form_data and have_data_entry(form_data, 'applyfilters'):
@ -736,11 +745,26 @@ class HttpHandler(BaseHTTPRequestHandler):
sort_dir = get_data_entry(form_data, 'sort_dir')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
if have_data_entry(form_data, 'state'):
state_ind = get_data_entry(form_data, 'state')
if state_ind != -1:
try:
state = BidStates(state_ind)
except Exception:
raise ValueError('Invalid state')
filters['bid_state_ind'] = state_ind
if have_data_entry(form_data, 'with_expired'):
with_expired = toBool(get_data_entry(form_data, 'with_expired'))
filters['with_expired'] = with_expired
set_pagination_filters(form_data, filters)
bids = swap_client.listBids(sent=sent, filters=filters)
page_data = {
'bid_states': listBidStates()
}
template = env.get_template('bids.html')
return bytes(template.render(
title=self.server.title,
@ -748,6 +772,7 @@ class HttpHandler(BaseHTTPRequestHandler):
page_type='Sent' if sent else 'Received',
messages=messages,
filters=filters,
data=page_data,
bids=[(format_timestamp(b[0]),
b[2].hex(), b[3].hex(), strBidState(b[5]), strTxState(b[7]), strTxState(b[8]), b[11]) for b in bids],
form_id=os.urandom(8).hex(),
@ -1003,6 +1028,8 @@ class HttpHandler(BaseHTTPRequestHandler):
return self.page_bids(url_split, post_string)
if url_split[1] == 'sentbids':
return self.page_bids(url_split, post_string, sent=True)
if url_split[1] == 'availablebids':
return self.page_bids(url_split, post_string, available=True)
if url_split[1] == 'watched':
return self.page_watched(url_split, post_string)
if url_split[1] == 'smsgaddresses':

View file

@ -12,19 +12,21 @@ import basicswap.contrib.ed25519_fast as edf
import basicswap.ed25519_fast_util as edu
import basicswap.util_xmr as xmr_util
from coincurve.ed25519 import (
ed25519_add,
ed25519_get_pubkey,
ed25519_scalar_add,
ed25519_add)
)
from coincurve.keys import PrivateKey
from coincurve.dleag import (
verify_ed25519_point,
dleag_proof_len,
dleag_prove,
dleag_verify,
dleag_prove)
dleag_proof_len,
verify_ed25519_point,
)
from .util import (
ensure,
dumpj,
ensure,
make_int,
TemporaryError)
from .rpc_xmr import (
@ -33,9 +35,7 @@ from .rpc_xmr import (
make_xmr_wallet_rpc_func)
from .util import (
b2i, b2h)
from .chainparams import CoinInterface, Coins
XMR_COIN = 10 ** 12
from .chainparams import XMR_COIN, CoinInterface, Coins
class XMRInterface(CoinInterface):
@ -155,7 +155,6 @@ class XMRInterface(CoinInterface):
def getNewAddress(self, placeholder):
with self._mx_wallet:
self._log.warning('TODO - subaddress?')
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
return self.rpc_wallet_cb('create_address', {'account_index': 0})['address']

View file

@ -20,6 +20,19 @@
<option value="desc"{% if filters.sort_dir=='desc' %} selected{% endif %}>Descending</option>
</select>
</td></tr>
<tr><td>State</td><td>
<select name="state">
<option value="-1"{% if filters.bid_state_ind==-1 %} selected{% endif %}>-- Any --</option>
{% for s in data.bid_states %}
<option value="{{ s[0] }}"{% if filters.bid_state_ind==s[0] %} selected{% endif %}>{{ s[1] }}</option>
{% endfor %}
</select>
<tr><td>Include Expired</td><td>
<select name="with_expired">
<option value="true"{% if filters.with_expired==true %} selected{% endif %}>Include</option>
<option value="false"{% if filters.with_expired==false %} selected{% endif %}>Exclude</option>
</select>
</td></tr>
<tr><td><input type="submit" name='applyfilters' value="Apply Filters"></td><td><input type="submit" name='clearfilters' value="Clear Filters"></td></tr>
<tr><td><input type="submit" name='pageback' value="Page Back"></td><td>Page: {{ filters.page_no }}</td><td><input type="submit" name='pageforwards' value="Page Forwards"></td></tr>

View file

@ -16,6 +16,7 @@ Version: {{ version }}
<a href="/active">Swaps in Progress: {{ summary.num_swapping }}</a><br/>
<a href="/offers">Network Offers: {{ summary.num_network_offers }}</a><br/>
<a href="/sentoffers">Sent Offers: {{ summary.num_sent_offers }}</a><br/>
<a href="/availablebids">Available Bids: {{ summary.num_available_bids }}</a><br/>
<a href="/bids">Received Bids: {{ summary.num_recv_bids }}</a><br/>
<a href="/sentbids">Sent Bids: {{ summary.num_sent_bids }}</a><br/>
<a href="/watched">Watched Outputs: {{ summary.num_watched_outputs }}</a><br/>

View file

@ -9,8 +9,8 @@
export RESET_TEST=true
export TEST_PATH=/tmp/test_persistent
mkdir -p ${TEST_PATH}/bin/{particl,monero,bitcoin}
cp ~/tmp/particl-0.21.2.9-x86_64-linux-gnu.tar.gz ${TEST_PATH}/bin/particl
cp ~/tmp/bitcoin-0.21.1-x86_64-linux-gnu.tar.gz ${TEST_PATH}/bin/bitcoin
cp ~/tmp/particl-0.21.2.9-x86_64-linux-gnu_nousb.tar.gz ${TEST_PATH}/bin/particl
cp ~/tmp/bitcoin-22.0-x86_64-linux-gnu.tar.gz ${TEST_PATH}/bin/bitcoin
cp ~/tmp/monero-linux-x64-v0.17.3.0.tar.bz2 ${TEST_PATH}/bin/monero/monero-0.17.3.0-x86_64-linux-gnu.tar.bz2
export PYTHONPATH=$(pwd)
python tests/basicswap/extended/test_xmr_persistent.py

View file

@ -46,8 +46,8 @@ from basicswap.rpc import (
waitForRPC,
)
from basicswap.rpc_xmr import (
callrpc_xmr_na,
callrpc_xmr,
callrpc_xmr_na,
)
from basicswap.interface_xmr import (
XMR_COIN,