ui: Fix active sent bids count.

This commit is contained in:
tecnovert 2023-06-28 19:27:44 +02:00
parent eb44dc9626
commit 00bebfa371
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
5 changed files with 70 additions and 20 deletions

View file

@ -1051,7 +1051,7 @@ class BasicSwap(BaseApp):
self.removeWatchedOutput(Coins(offer.coin_from), bid.bid_id, None)
self.removeWatchedOutput(Coins(offer.coin_to), bid.bid_id, None)
if bid.state == BidStates.BID_ABANDONED or bid.state == BidStates.SWAP_COMPLETED:
if bid.state in (BidStates.BID_ABANDONED, BidStates.SWAP_COMPLETED):
# Return unused addrs to pool
itx_state = bid.getITxState()
ptx_state = bid.getPTxState()
@ -5824,12 +5824,13 @@ class BasicSwap(BaseApp):
now: int = self.getTime()
q_str = '''SELECT
COUNT(CASE WHEN b.was_sent THEN 1 ELSE NULL END) AS count_sent,
COUNT(CASE WHEN b.was_sent AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_sent_active,
COUNT(CASE WHEN b.was_sent AND s.swap_ended = 0 AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_sent_active,
COUNT(CASE WHEN b.was_received THEN 1 ELSE NULL END) AS count_received,
COUNT(CASE WHEN b.was_received AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_available
FROM bids b
JOIN offers o ON b.offer_id = o.offer_id
WHERE b.active_ind = 1'''.format(BidStates.BID_RECEIVED, now, now, BidStates.BID_RECEIVED, now, now)
JOIN bidstates s ON b.state = s.state_id
WHERE b.active_ind = 1'''.format(now, now, BidStates.BID_RECEIVED, now, now)
q = self.engine.execute(q_str).first()
bids_sent = q[0]
bids_sent_active = q[1]

View file

@ -464,6 +464,25 @@ def getLastBidState(packed_states):
return BidStates.BID_STATE_UNKNOWN
def strSwapType(swap_type):
if swap_type == SwapTypes.SELLER_FIRST:
return 'seller_first'
if swap_type == SwapTypes.XMR_SWAP:
return 'xmr_swap'
return None
def strSwapDesc(swap_type):
if swap_type == SwapTypes.SELLER_FIRST:
return 'Secret Hash'
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]
def isActiveBidState(state):
if state >= BidStates.BID_ACCEPTED and state < BidStates.SWAP_COMPLETED:
return True
@ -492,20 +511,24 @@ def isActiveBidState(state):
return False
def strSwapType(swap_type):
if swap_type == SwapTypes.SELLER_FIRST:
return 'seller_first'
if swap_type == SwapTypes.XMR_SWAP:
return 'xmr_swap'
return None
def isErrorBidState(state):
return state in (
BidStates.BID_STALLED_FOR_TEST,
BidStates.BID_ERROR,
)
def strSwapDesc(swap_type):
if swap_type == SwapTypes.SELLER_FIRST:
return 'Secret Hash'
if swap_type == SwapTypes.XMR_SWAP:
return 'Adaptor Sig'
return None
def isFailingBidState(state):
return state in (
BidStates.BID_STALLED_FOR_TEST,
BidStates.BID_ERROR,
BidStates.XMR_SWAP_SCRIPT_TX_PREREFUND,
BidStates.XMR_SWAP_NOSCRIPT_TX_RECOVERED,
BidStates.XMR_SWAP_FAILED_REFUNDED,
BidStates.XMR_SWAP_FAILED_SWIPED,
BidStates.XMR_SWAP_FAILED,
)
inactive_states = [BidStates.SWAP_COMPLETED, BidStates.BID_ERROR, BidStates.BID_REJECTED, BidStates.SWAP_TIMEDOUT, BidStates.BID_ABANDONED]
def isFinalBidState(state):
return state in inactive_states

View file

@ -12,8 +12,8 @@ from enum import IntEnum, auto
from sqlalchemy.ext.declarative import declarative_base
CURRENT_DB_VERSION = 19
CURRENT_DB_DATA_VERSION = 2
CURRENT_DB_VERSION = 20
CURRENT_DB_DATA_VERSION = 3
Base = declarative_base()
@ -487,6 +487,9 @@ class BidState(Base):
state_id = sa.Column(sa.Integer)
label = sa.Column(sa.String)
in_progress = sa.Column(sa.Integer)
in_error = sa.Column(sa.Integer)
swap_failed = sa.Column(sa.Integer)
swap_ended = sa.Column(sa.Integer)
note = sa.Column(sa.String)
created_at = sa.Column(sa.BigInteger)

View file

@ -18,7 +18,11 @@ from .db import (
from .basicswap_util import (
BidStates,
strBidState,
isActiveBidState)
isActiveBidState,
isErrorBidState,
isFailingBidState,
isFinalBidState,
)
def upgradeDatabaseData(self, data_version):
@ -56,10 +60,13 @@ def upgradeDatabaseData(self, data_version):
active_ind=1,
state_id=int(state),
in_progress=isActiveBidState(state),
in_error=isErrorBidState(state),
swap_failed=isFailingBidState(state),
swap_ended=isFinalBidState(state),
label=strBidState(state),
created_at=now))
if data_version < 2:
if data_version > 0 and data_version < 2:
for state in (BidStates.XMR_SWAP_MSG_SCRIPT_LOCK_TX_SIGS, BidStates.XMR_SWAP_MSG_SCRIPT_LOCK_SPEND_TX):
session.add(BidState(
active_ind=1,
@ -67,6 +74,12 @@ def upgradeDatabaseData(self, data_version):
in_progress=isActiveBidState(state),
label=strBidState(state),
created_at=now))
if data_version > 0 and data_version < 3:
for state in BidStates:
in_error = isErrorBidState(state)
swap_failed = isFailingBidState(state)
swap_ended = isFinalBidState(state)
session.execute('UPDATE bidstates SET in_error = :in_error, swap_failed = :swap_failed, swap_ended = :swap_ended WHERE state_id = :state_id', {'in_error': in_error, 'swap_failed': swap_failed, 'swap_ended': swap_ended, 'state_id': int(state)})
self.db_data_version = CURRENT_DB_DATA_VERSION
self.setIntKVInSession('db_data_version', self.db_data_version, session)
@ -248,6 +261,11 @@ def upgradeDatabase(self, db_version):
db_version += 1
session.execute('ALTER TABLE xmr_split_data ADD COLUMN addr_from STRING')
session.execute('ALTER TABLE xmr_split_data ADD COLUMN addr_to STRING')
elif current_version == 19:
db_version += 1
session.execute('ALTER TABLE bidstates ADD COLUMN in_error INTEGER')
session.execute('ALTER TABLE bidstates ADD COLUMN swap_failed INTEGER')
session.execute('ALTER TABLE bidstates ADD COLUMN swap_ended INTEGER')
if current_version != db_version:
self.db_version = db_version

View file

@ -2,6 +2,11 @@
Examples:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"coin_from":"btc","coin_to":"xmr","amt_from":10,"amt_to":10,"lockseconds":1200}' \
http://localhost:12701/json/offers/new
curl --header "Content-Type: application/json" \
--request POST \
--data '{"show_extra":true}' \