Show error when auto-accepting a bid fails.

This commit is contained in:
tecnovert
2024-01-24 23:12:18 +02:00
parent bcfd63037a
commit f5d4b8dc0d
8 changed files with 121 additions and 32 deletions

View File

@@ -2432,7 +2432,6 @@ class BasicSwap(BaseApp):
reverse_bid: bool = self.is_reverse_ads_bid(offer.coin_from)
if reverse_bid:
return self.acceptADSReverseBid(bid_id)
return self.acceptXmrBid(bid_id)
if bid.contract_count is None:
@@ -4301,23 +4300,28 @@ class BasicSwap(BaseApp):
self.closeSession(session)
def countQueuedActions(self, session, bid_id: bytes, action_type) -> int:
q = session.query(Action).filter(sa.and_(Action.active_ind == 1, Action.linked_id == bid_id, Action.action_type == int(action_type)))
q = session.query(Action).filter(sa.and_(Action.active_ind == 1, Action.linked_id == bid_id))
if action_type is not None:
q.filter(Action.action_type == int(action_type))
return q.count()
def checkQueuedActions(self) -> None:
self.mxDB.acquire()
now: int = self.getTime()
session = None
reload_in_progress = False
reload_in_progress: bool = False
try:
session = scoped_session(self.session_factory)
q = session.query(Action).filter(sa.and_(Action.active_ind == 1, Action.trigger_at <= now))
for row in q:
accepting_bid: bool = False
try:
if row.action_type == ActionTypes.ACCEPT_BID:
accepting_bid = True
self.acceptBid(row.linked_id)
elif row.action_type == ActionTypes.ACCEPT_XMR_BID:
accepting_bid = True
self.acceptXmrBid(row.linked_id)
elif row.action_type == ActionTypes.SIGN_XMR_SWAP_LOCK_TX_A:
self.sendXmrBidTxnSigsFtoL(row.linked_id, session)
@@ -4338,11 +4342,34 @@ class BasicSwap(BaseApp):
elif row.action_type == ActionTypes.REDEEM_ITX:
atomic_swap_1.redeemITx(self, row.linked_id, session)
elif row.action_type == ActionTypes.ACCEPT_AS_REV_BID:
accepting_bid = True
self.acceptADSReverseBid(row.linked_id)
else:
self.log.warning('Unknown event type: %d', row.event_type)
except Exception as ex:
self.logException(f'checkQueuedActions failed: {ex}')
err_msg = f'checkQueuedActions failed: {ex}'
self.logException(err_msg)
bid_id = row.linked_id
# Failing to accept a bid should not set an error state as the bid has not begun yet
if accepting_bid:
self.logEvent(Concepts.BID,
bid_id,
EventLogTypes.ERROR,
err_msg,
session)
# If delaying with no (further) queued actions reset state
if self.countQueuedActions(session, bid_id, None) < 2:
bid = self.getBid(bid_id, session)
if bid and bid.state == BidStates.SWAP_DELAYING:
bid.setState(BidStates.BID_RECEIVED)
self.saveBidInSession(bid_id, bid, session)
else:
bid = self.getBid(bid_id, session)
if bid:
bid.setState(BidStates.BID_ERROR, err_msg)
self.saveBidInSession(bid_id, bid, session)
if self.debug:
session.execute('UPDATE actions SET active_ind = 2 WHERE trigger_at <= :now', {'now': now})

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019-2023 tecnovert
# Copyright (c) 2019-2024 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -327,11 +327,15 @@ class HttpHandler(BaseHTTPRequestHandler):
template = env.get_template('rpc.html')
coins = listAvailableCoins(swap_client, with_variants=False)
with_xmr: bool = any(c[0] == Coins.XMR for c in coins)
coins = [c for c in coins if c[0] != Coins.XMR]
coins.append((-5, 'Litecoin MWEB Wallet'))
coins.append((-2, 'Monero'))
coins.append((-3, 'Monero JSON'))
coins.append((-4, 'Monero Wallet'))
if any(c[0] == Coins.LTC for c in coins):
coins.append((-5, 'Litecoin MWEB Wallet'))
if with_xmr:
coins.append((-2, 'Monero'))
coins.append((-3, 'Monero JSON'))
coins.append((-4, 'Monero Wallet'))
return self.render_template(template, {
'messages': messages,

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2023 tecnovert
# Copyright (c) 2020-2024 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -1375,6 +1375,20 @@ class BTCInterface(CoinInterface):
for u in unspent:
if u['spendable'] is not True:
continue
if 'address' not in u:
continue
if 'desc' in u:
desc = u['desc']
if self.using_segwit:
if self.use_p2shp2wsh():
if not desc.startswith('sh(wpkh'):
continue
else:
if not desc.startswith('wpkh'):
continue
else:
if not desc.startswith('pkh'):
continue
unspent_addr[u['address']] = unspent_addr.get(u['address'], 0) + self.make_int(u['amount'], r=1)
return unspent_addr

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2023 tecnovert
# Copyright (c) 2020-2024 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -141,6 +141,17 @@ class PARTInterface(BTCInterface):
tx_vsize += 204 if redeem else 187
return tx_vsize
def getUnspentsByAddr(self):
unspent_addr = dict()
unspent = self.rpc_wallet('listunspent')
for u in unspent:
if u['spendable'] is not True:
continue
if 'address' not in u:
continue
unspent_addr[u['address']] = unspent_addr.get(u['address'], 0) + self.make_int(u['amount'], r=1)
return unspent_addr
class PARTInterfaceBlind(PARTInterface):
@staticmethod

View File

@@ -84,11 +84,14 @@ def js_coins(self, url_split, post_string, is_json) -> bytes:
for coin in Coins:
cc = swap_client.coin_clients[coin]
coin_chainparams = chainparams[cc['coin']]
coin_active: bool = False if cc['connection_type'] == 'none' else True
if coin == Coins.LTC_MWEB:
coin_active = False
entry = {
'id': int(coin),
'ticker': coin_chainparams['ticker'],
'name': getCoinName(coin),
'active': False if cc['connection_type'] == 'none' else True,
'active': coin_active,
'decimal_places': coin_chainparams['decimal_places'],
}
if coin == Coins.PART_ANON: