mirror of
https://github.com/basicswap/basicswap.git
synced 2025-03-12 09:38:03 +00:00
ui: Add option to remove expired offers and bids.
This commit is contained in:
parent
1dcd750fea
commit
cbb3d0ac02
8 changed files with 138 additions and 40 deletions
|
@ -145,6 +145,7 @@ from .basicswap_util import (
|
|||
NotificationTypes as NT,
|
||||
AutomationOverrideOptions,
|
||||
VisibilityOverrideOptions,
|
||||
inactive_states,
|
||||
)
|
||||
|
||||
|
||||
|
@ -6109,6 +6110,12 @@ class BasicSwap(BaseApp):
|
|||
session.remove()
|
||||
self.mxDB.release()
|
||||
|
||||
def activeBidsQueryStr(self, now: int, offer_table: str = 'offers', bids_table: str = 'bids'):
|
||||
offers_inset = f' AND {offer_table}.expire_at > {now}' if offer_table != '' else ''
|
||||
|
||||
inactive_states_str = ', '.join([str(int(s)) for s in inactive_states])
|
||||
return f' ({bids_table}.state NOT IN ({inactive_states_str}) AND ({bids_table}.state > {BidStates.BID_RECEIVED} OR ({bids_table}.expire_at > {now}{offers_inset}))) '
|
||||
|
||||
def listBids(self, sent=False, offer_id=None, for_html=False, filters={}):
|
||||
self.mxDB.acquire()
|
||||
try:
|
||||
|
@ -6139,7 +6146,7 @@ class BasicSwap(BaseApp):
|
|||
with_available_or_active = filters.get('with_available_or_active', False)
|
||||
with_expired = filters.get('with_expired', True)
|
||||
if with_available_or_active:
|
||||
query_str += 'AND (bids.state NOT IN ({}, {}, {}, {}, {}) AND (bids.state > {} OR (bids.expire_at > {} AND offers.expire_at > {}))) '.format(BidStates.SWAP_COMPLETED, BidStates.BID_ERROR, BidStates.BID_REJECTED, BidStates.SWAP_TIMEDOUT, BidStates.BID_ABANDONED, BidStates.BID_RECEIVED, now, now)
|
||||
query_str += ' AND ' + self.activeBidsQueryStr(now)
|
||||
else:
|
||||
if with_expired is not True:
|
||||
query_str += 'AND bids.expire_at > {} AND offers.expire_at > {} '.format(now, now)
|
||||
|
|
|
@ -506,3 +506,6 @@ def strSwapDesc(swap_type):
|
|||
if swap_type == SwapTypes.XMR_SWAP:
|
||||
return 'Adaptor Sig'
|
||||
return None
|
||||
|
||||
|
||||
inactive_states = [BidStates.SWAP_COMPLETED, BidStates.BID_ERROR, BidStates.BID_REJECTED, BidStates.SWAP_TIMEDOUT, BidStates.BID_ABANDONED]
|
||||
|
|
54
basicswap/db_util.py
Normal file
54
basicswap/db_util.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2023 The BSX Developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
from .db import (
|
||||
Concepts,
|
||||
)
|
||||
|
||||
|
||||
def remove_expired_data(self):
|
||||
self.log.warning('Removing expired data')
|
||||
now: int = self.getTime()
|
||||
try:
|
||||
session = self.openSession()
|
||||
|
||||
active_bids_insert = self.activeBidsQueryStr(now, '', 'b2')
|
||||
query_str = f'''
|
||||
SELECT o.offer_id FROM offers o
|
||||
WHERE o.expire_at <= :now AND 0 = (SELECT COUNT(*) FROM bids b2 WHERE b2.offer_id = o.offer_id AND {active_bids_insert})
|
||||
'''
|
||||
num_offers = 0
|
||||
num_bids = 0
|
||||
offer_rows = session.execute(query_str, {'now': now})
|
||||
for offer_row in offer_rows:
|
||||
num_offers += 1
|
||||
bid_rows = session.execute('SELECT bids.bid_id FROM bids WHERE bids.offer_id = :offer_id', {'offer_id': offer_row[0]})
|
||||
for bid_row in bid_rows:
|
||||
num_bids += 1
|
||||
session.execute('DELETE FROM transactions WHERE transactions.bid_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM eventlog WHERE eventlog.linked_type = :type_ind AND eventlog.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM automationlinks WHERE automationlinks.linked_type = :type_ind AND automationlinks.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM prefunded_transactions WHERE prefunded_transactions.linked_type = :type_ind AND prefunded_transactions.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM history WHERE history.concept_type = :type_ind AND history.concept_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM xmr_swaps WHERE xmr_swaps.bid_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM actions WHERE actions.linked_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM addresspool WHERE addresspool.bid_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM xmr_split_data WHERE xmr_split_data.bid_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
session.execute('DELETE FROM bids WHERE bids.bid_id = :bid_id', {'bid_id': bid_row[0]})
|
||||
|
||||
session.execute('DELETE FROM eventlog WHERE eventlog.linked_type = :type_ind AND eventlog.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM automationlinks WHERE automationlinks.linked_type = :type_ind AND automationlinks.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM prefunded_transactions WHERE prefunded_transactions.linked_type = :type_ind AND prefunded_transactions.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM history WHERE history.concept_type = :type_ind AND history.concept_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM xmr_offers WHERE xmr_offers.offer_id = :offer_id', {'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM sentoffers WHERE sentoffers.offer_id = :offer_id', {'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM actions WHERE actions.linked_id = :offer_id', {'offer_id': offer_row[0]})
|
||||
session.execute('DELETE FROM offers WHERE offers.offer_id = :offer_id', {'offer_id': offer_row[0]})
|
||||
|
||||
self.log.warning(f'Removed data for {num_offers} expired offers and {num_bids} bids.')
|
||||
|
||||
finally:
|
||||
self.closeSession(session)
|
|
@ -38,7 +38,6 @@ from .ui.util import (
|
|||
getCoinName,
|
||||
get_data_entry,
|
||||
get_data_entry_or,
|
||||
have_data_entry,
|
||||
listAvailableCoins,
|
||||
)
|
||||
from .ui.page_automation import (
|
||||
|
@ -55,6 +54,7 @@ from .ui.page_settings import page_settings
|
|||
from .ui.page_encryption import page_changepassword, page_unlock, page_lock
|
||||
from .ui.page_identity import page_identity
|
||||
from .ui.page_smsgaddresses import page_smsgaddresses
|
||||
from .ui.page_debug import page_debug
|
||||
|
||||
env = Environment(loader=PackageLoader('basicswap', 'templates'))
|
||||
env.filters['formatts'] = format_timestamp
|
||||
|
@ -333,31 +333,6 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
'summary': summary,
|
||||
})
|
||||
|
||||
def page_debug(self, url_split, post_string):
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
summary = swap_client.getSummary()
|
||||
|
||||
result = None
|
||||
messages = []
|
||||
err_messages = []
|
||||
form_data = self.checkForm(post_string, 'wallets', err_messages)
|
||||
if form_data:
|
||||
if have_data_entry(form_data, 'reinit_xmr'):
|
||||
try:
|
||||
swap_client.initialiseWallet(Coins.XMR)
|
||||
messages.append('Done.')
|
||||
except Exception as a:
|
||||
err_messages.append('Failed.')
|
||||
|
||||
template = env.get_template('debug.html')
|
||||
return self.render_template(template, {
|
||||
'messages': messages,
|
||||
'err_messages': err_messages,
|
||||
'result': result,
|
||||
'summary': summary,
|
||||
})
|
||||
|
||||
def page_active(self, url_split, post_string):
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
|
@ -502,7 +477,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
if page == 'rpc':
|
||||
return self.page_rpc(url_split, post_string)
|
||||
if page == 'debug':
|
||||
return self.page_debug(url_split, post_string)
|
||||
return page_debug(self, url_split, post_string)
|
||||
if page == 'explorers':
|
||||
return self.page_explorers(url_split, post_string)
|
||||
if page == 'offer':
|
||||
|
|
|
@ -67,6 +67,13 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<form method="post">
|
||||
<tr class="opacity-100 text-gray-500 dark:text-gray-100">
|
||||
<td class="py-3 px-6 bold">Remove expired offers and bids</td>
|
||||
<td td class="py-3 px-6 ">
|
||||
<button name="remove_expired" type="submit" value="Yes" class="flex flex-wrap justify-center py-2 px-4 bg-blue-500 hover:bg-blue-600 font-medium text-sm text-white border border-blue-500 rounded-md shadow-button focus:ring-0 focus:outline-none" onclick="return confirmRemoveExpired();">
|
||||
Yes - Remove Data</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="opacity-100 text-gray-500 dark:text-gray-100">
|
||||
<td class="py-3 px-6 bold">Reinitialise XMR wallet</td>
|
||||
<td td class="py-3 px-6 ">
|
||||
|
@ -82,8 +89,8 @@
|
|||
</g>
|
||||
</svg>Yes - Start Process</button>
|
||||
</td>
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
</tr>
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -121,4 +128,9 @@
|
|||
{% include 'footer.html' %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
function confirmRemoveExpired() {
|
||||
return confirm("This will remove all expired offers and bids from the database - Are you sure?");
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
|
|
@ -142,18 +142,10 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
<!-- havedata -->
|
||||
</div> {% endfor %} <script>
|
||||
function confirmReseed() {
|
||||
return confirm("Are you sure?\nBackup your wallet before and after.\nWon't detect used keys.\nShould only be used for new wallets.");
|
||||
}
|
||||
|
||||
function confirmWithdrawal() {
|
||||
return confirm("Are you sure?");
|
||||
}
|
||||
</script>
|
||||
</div> {% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
54
basicswap/ui/page_debug.py
Normal file
54
basicswap/ui/page_debug.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2023 The BSX Developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import traceback
|
||||
from .util import (
|
||||
have_data_entry,
|
||||
)
|
||||
from basicswap.chainparams import (
|
||||
Coins,
|
||||
)
|
||||
from basicswap.db_util import (
|
||||
remove_expired_data,
|
||||
)
|
||||
|
||||
|
||||
def page_debug(self, url_split, post_string):
|
||||
server = self.server
|
||||
swap_client = server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
summary = swap_client.getSummary()
|
||||
|
||||
result = None
|
||||
messages = []
|
||||
err_messages = []
|
||||
form_data = self.checkForm(post_string, 'wallets', err_messages)
|
||||
if form_data:
|
||||
if have_data_entry(form_data, 'reinit_xmr'):
|
||||
try:
|
||||
swap_client.initialiseWallet(Coins.XMR)
|
||||
messages.append('Done.')
|
||||
except Exception as e:
|
||||
err_messages.append('Failed.')
|
||||
|
||||
if have_data_entry(form_data, 'remove_expired'):
|
||||
try:
|
||||
remove_expired_data(swap_client)
|
||||
messages.append('Done.')
|
||||
except Exception as e:
|
||||
if swap_client.debug is True:
|
||||
swap_client.log.error(traceback.format_exc())
|
||||
else:
|
||||
swap_client.log.error(f'remove_expired_data: {e}')
|
||||
err_messages.append('Failed.')
|
||||
|
||||
template = server.env.get_template('debug.html')
|
||||
return self.render_template(template, {
|
||||
'messages': messages,
|
||||
'err_messages': err_messages,
|
||||
'result': result,
|
||||
'summary': summary,
|
||||
})
|
|
@ -3,6 +3,7 @@
|
|||
==============
|
||||
|
||||
- cores: Raised Particl and Monero daemon version.
|
||||
- ui: Add debug option to remove expired offers, bids and transactions.
|
||||
|
||||
|
||||
0.0.62
|
||||
|
|
Loading…
Reference in a new issue