From 28fc4817c0ea027983b70ef16d00682c28446ac0 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Wed, 31 Jan 2024 20:40:22 +0200 Subject: [PATCH] debug: Add ui option to schedule bid actions. --- basicswap/basicswap.py | 46 +++++++++++++++++++----- basicswap/basicswap_util.py | 1 + basicswap/templates/bid_xmr.html | 29 ++++++++------- basicswap/ui/page_bids.py | 15 ++++++-- basicswap/ui/util.py | 22 ++++++++---- tests/basicswap/selenium/test_wallets.py | 6 ++-- 6 files changed, 86 insertions(+), 33 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 1714c96..6356128 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -236,6 +236,7 @@ class BasicSwap(BaseApp): self.check_xmr_swaps_seconds = self.get_int_setting('check_xmr_swaps_seconds', 20, 1, 10 * 60) self.startup_tries = self.get_int_setting('startup_tries', 21, 1, 100) # Seconds waited for will be (x(1 + x+1) / 2 self.debug_ui = self.settings.get('debug_ui', False) + self._debug_cases = [] self._last_checked_progress = 0 self._last_checked_watched = 0 self._last_checked_expired = 0 @@ -2098,6 +2099,16 @@ class BasicSwap(BaseApp): action_type=action_type, linked_id=linked_id) session.add(action) + for debug_case in self._debug_cases: + bid_id, debug_ind = debug_case + if bid_id == linked_id and debug_ind == DebugTypes.DUPLICATE_ACTIONS: + action = Action( + active_ind=1, + created_at=now, + trigger_at=now + delay + 3, + action_type=action_type, + linked_id=linked_id) + session.add(action) def createAction(self, delay: int, action_type: int, linked_id: bytes) -> None: # self.log.debug('createAction %d %s', action_type, linked_id.hex()) @@ -5505,12 +5516,15 @@ class BasicSwap(BaseApp): txid = bytes.fromhex(ci_from.publishTx(xmr_swap.a_lock_spend_tx)) self.log.debug('Submitted lock spend txn %s to %s chain for bid %s', txid.hex(), ci_from.coin_name(), bid_id.hex()) self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_A_SPEND_TX_PUBLISHED, '', session) - bid.xmr_a_lock_spend_tx = SwapTx( - bid_id=bid_id, - tx_type=TxTypes.XMR_SWAP_A_LOCK_SPEND, - txid=txid, - ) - bid.xmr_a_lock_spend_tx.setState(TxStates.TX_NONE) + if bid.xmr_a_lock_spend_tx is None: + bid.xmr_a_lock_spend_tx = SwapTx( + bid_id=bid_id, + tx_type=TxTypes.XMR_SWAP_A_LOCK_SPEND, + txid=txid, + ) + bid.xmr_a_lock_spend_tx.setState(TxStates.TX_NONE) + else: + self.log.warning('Chain A lock TX %s already exists for bid %s', bid.xmr_a_lock_spend_tx.txid.hex(), bid_id.hex()) self.saveBidInSession(bid_id, bid, session, xmr_swap, save_in_progress=offer) @@ -6182,6 +6196,8 @@ class BasicSwap(BaseApp): def manualBidUpdate(self, bid_id: bytes, data): self.log.info('Manually updating bid %s', bid_id.hex()) self.mxDB.acquire() + + add_bid_action = -1 try: bid, offer = self.getBidAndOffer(bid_id) ensure(bid, 'Bid not found {}'.format(bid_id.hex())) @@ -6190,7 +6206,12 @@ class BasicSwap(BaseApp): has_changed = False if bid.state != data['bid_state']: bid.setState(data['bid_state']) - self.log.debug('Set state to %s', strBidState(bid.state)) + self.log.warning('Set state to %s', strBidState(bid.state)) + has_changed = True + + if data['bid_action'] != -1: + self.log.warning('Adding action', ActionTypes(data['bid_action']).name) + add_bid_action = ActionTypes(data['bid_action']) has_changed = True if bid.debug_ind != data['debug_ind']: @@ -6211,6 +6232,10 @@ class BasicSwap(BaseApp): if bid.state and isActiveBidState(bid.state): activate_bid = True + if add_bid_action > -1: + delay = self.get_delay_event_seconds() + self.createActionInSession(delay, add_bid_action, bid_id, session) + if activate_bid: self.activateBid(session, bid) else: @@ -7074,8 +7099,13 @@ class BasicSwap(BaseApp): xmr_swap.a_lock_refund_swipe_tx = ci.setTxSignature(spend_tx, witness_stack) - def setBidDebugInd(self, bid_id: bytes, debug_ind) -> None: + def setBidDebugInd(self, bid_id: bytes, debug_ind, add_to_bid: bool = True) -> None: self.log.debug('Bid %s Setting debug flag: %s', bid_id.hex(), debug_ind) + + self._debug_cases.append((bid_id, debug_ind)) + if add_to_bid is False: + return + bid = self.getBid(bid_id) bid.debug_ind = debug_ind diff --git a/basicswap/basicswap_util.py b/basicswap/basicswap_util.py index 5828c37..996e783 100644 --- a/basicswap/basicswap_util.py +++ b/basicswap/basicswap_util.py @@ -198,6 +198,7 @@ class DebugTypes(IntEnum): SKIP_LOCK_TX_REFUND = auto() SEND_LOCKED_XMR = auto() B_LOCK_TX_MISSED_SEND = auto() + DUPLICATE_ACTIONS = auto() class NotificationTypes(IntEnum): diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html index 0915263..882addd 100644 --- a/basicswap/templates/bid_xmr.html +++ b/basicswap/templates/bid_xmr.html @@ -1,4 +1,6 @@ {% include 'header.html' %} +{% from 'style.html' import input_arrow_down_svg %} +
@@ -503,10 +505,7 @@ View Transaction: -
- - - +
{{ input_arrow_down_svg | safe }} {% for s in data.bid_states %} @@ -736,13 +732,22 @@ {% if data.debug_ui == true %} + + Add Bid Action: + +
{{ input_arrow_down_svg | safe }} + +
+ + Debug Option -
- - - +
{{ input_arrow_down_svg | safe }}