debug: Add ui option to schedule bid actions.

2024-05-20_merge
tecnovert 11 months ago
parent 9ee6669179
commit 28fc4817c0
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 46
      basicswap/basicswap.py
  2. 1
      basicswap/basicswap_util.py
  3. 29
      basicswap/templates/bid_xmr.html
  4. 15
      basicswap/ui/page_bids.py
  5. 20
      basicswap/ui/util.py
  6. 6
      tests/basicswap/selenium/test_wallets.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.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.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_ui = self.settings.get('debug_ui', False)
self._debug_cases = []
self._last_checked_progress = 0 self._last_checked_progress = 0
self._last_checked_watched = 0 self._last_checked_watched = 0
self._last_checked_expired = 0 self._last_checked_expired = 0
@ -2098,6 +2099,16 @@ class BasicSwap(BaseApp):
action_type=action_type, action_type=action_type,
linked_id=linked_id) linked_id=linked_id)
session.add(action) 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: def createAction(self, delay: int, action_type: int, linked_id: bytes) -> None:
# self.log.debug('createAction %d %s', action_type, linked_id.hex()) # 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)) 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.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) self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_A_SPEND_TX_PUBLISHED, '', session)
bid.xmr_a_lock_spend_tx = SwapTx( if bid.xmr_a_lock_spend_tx is None:
bid_id=bid_id, bid.xmr_a_lock_spend_tx = SwapTx(
tx_type=TxTypes.XMR_SWAP_A_LOCK_SPEND, bid_id=bid_id,
txid=txid, tx_type=TxTypes.XMR_SWAP_A_LOCK_SPEND,
) txid=txid,
bid.xmr_a_lock_spend_tx.setState(TxStates.TX_NONE) )
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) 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): def manualBidUpdate(self, bid_id: bytes, data):
self.log.info('Manually updating bid %s', bid_id.hex()) self.log.info('Manually updating bid %s', bid_id.hex())
self.mxDB.acquire() self.mxDB.acquire()
add_bid_action = -1
try: try:
bid, offer = self.getBidAndOffer(bid_id) bid, offer = self.getBidAndOffer(bid_id)
ensure(bid, 'Bid not found {}'.format(bid_id.hex())) ensure(bid, 'Bid not found {}'.format(bid_id.hex()))
@ -6190,7 +6206,12 @@ class BasicSwap(BaseApp):
has_changed = False has_changed = False
if bid.state != data['bid_state']: if bid.state != data['bid_state']:
bid.setState(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 has_changed = True
if bid.debug_ind != data['debug_ind']: if bid.debug_ind != data['debug_ind']:
@ -6211,6 +6232,10 @@ class BasicSwap(BaseApp):
if bid.state and isActiveBidState(bid.state): if bid.state and isActiveBidState(bid.state):
activate_bid = True 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: if activate_bid:
self.activateBid(session, bid) self.activateBid(session, bid)
else: else:
@ -7074,8 +7099,13 @@ class BasicSwap(BaseApp):
xmr_swap.a_lock_refund_swipe_tx = ci.setTxSignature(spend_tx, witness_stack) 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.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 = self.getBid(bid_id)
bid.debug_ind = debug_ind bid.debug_ind = debug_ind

@ -198,6 +198,7 @@ class DebugTypes(IntEnum):
SKIP_LOCK_TX_REFUND = auto() SKIP_LOCK_TX_REFUND = auto()
SEND_LOCKED_XMR = auto() SEND_LOCKED_XMR = auto()
B_LOCK_TX_MISSED_SEND = auto() B_LOCK_TX_MISSED_SEND = auto()
DUPLICATE_ACTIONS = auto()
class NotificationTypes(IntEnum): class NotificationTypes(IntEnum):

@ -1,4 +1,6 @@
{% include 'header.html' %} {% include 'header.html' %}
{% from 'style.html' import input_arrow_down_svg %}
<div class="container mx-auto"> <div class="container mx-auto">
<section class="p-5 mt-5"> <section class="p-5 mt-5">
<div class="flex flex-wrap items-center -m-2"> <div class="flex flex-wrap items-center -m-2">
@ -503,10 +505,7 @@
<tr class="opacity-100 text-gray-500 dark:text-gray-100"> <tr class="opacity-100 text-gray-500 dark:text-gray-100">
<td class="py-3 px-6 bold">View Transaction:</td> <td class="py-3 px-6 bold">View Transaction:</td>
<td class="py-3 px-6 bold"> <td class="py-3 px-6 bold">
<div class="relative"> <div class="relative">{{ input_arrow_down_svg | safe }}
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"></path>
</svg>
<select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="view_tx"> <select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="view_tx">
{% if data.txns|length %} {% for tx in data.txns %} {% if data.txns|length %} {% for tx in data.txns %}
<option value="{{ tx.txid }}" {% if data.view_tx_ind==tx.txid %} selected{% endif %}>{{ tx.type }} {{ tx.txid }}</option> <option value="{{ tx.txid }}" {% if data.view_tx_ind==tx.txid %} selected{% endif %}>{{ tx.type }} {{ tx.txid }}</option>
@ -723,10 +722,7 @@
<tr class="opacity-100 text-gray-500 dark:text-gray-100"> <tr class="opacity-100 text-gray-500 dark:text-gray-100">
<td class="py-3 px-6 bold">Change Bid State:</td> <td class="py-3 px-6 bold">Change Bid State:</td>
<td class="py-3 px-6"> <td class="py-3 px-6">
<div class="relative"> <div class="relative">{{ input_arrow_down_svg | safe }}
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"></path>
</svg>
<select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="new_state"> <select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="new_state">
{% for s in data.bid_states %} {% for s in data.bid_states %}
<option value="{{ s[0] }}" {% if data.bid_state_ind==s[0] %} selected{% endif %}>{{ s[1] }}</option> <option value="{{ s[0] }}" {% if data.bid_state_ind==s[0] %} selected{% endif %}>{{ s[1] }}</option>
@ -736,13 +732,22 @@
</td> </td>
</tr> </tr>
{% if data.debug_ui == true %} {% if data.debug_ui == true %}
<tr class="opacity-100 text-gray-500 dark:text-gray-100">
<td class="py-3 px-6 bold">Add Bid Action:</td>
<td class="py-3 px-6">
<div class="relative">{{ input_arrow_down_svg | safe }}
<select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="new_action">
{% for a in data.bid_actions %}
<option value="{{ a[0] }}">{{ a[1] }}</option>
{% endfor %}
</select>
</div>
</td>
</tr>
<tr class="opacity-100 text-gray-500 dark:text-gray-100"> <tr class="opacity-100 text-gray-500 dark:text-gray-100">
<td class="py-3 px-6 bold">Debug Option</td> <td class="py-3 px-6 bold">Debug Option</td>
<td class="py-3 px-6"> <td class="py-3 px-6">
<div class="relative"> <div class="relative">{{ input_arrow_down_svg | safe }}
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"></path>
</svg>
<select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="debugind"> <select class="bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-gray-50 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" name="debugind">
<option{% if data.debug_ind=="-1" %} selected{% endif %} value="-1">None</option> <option{% if data.debug_ind=="-1" %} selected{% endif %} value="-1">None</option>
{% for a in data.debug_options %} {% for a in data.debug_options %}

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2022-2023 tecnovert # Copyright (c) 2022-2024 tecnovert
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -10,6 +10,7 @@ from .util import (
get_data_entry, get_data_entry,
have_data_entry, have_data_entry,
get_data_entry_or, get_data_entry_or,
listBidActions,
listBidStates, listBidStates,
listOldBidStates, listOldBidStates,
set_pagination_filters, set_pagination_filters,
@ -73,6 +74,7 @@ def page_bid(self, url_split, post_string):
elif b'edit_bid_submit' in form_data: elif b'edit_bid_submit' in form_data:
data = { data = {
'bid_state': int(form_data[b'new_state'][0]), 'bid_state': int(form_data[b'new_state'][0]),
'bid_action': int(get_data_entry_or(form_data, 'new_action', -1)),
'debug_ind': int(get_data_entry_or(form_data, 'debugind', -1)), 'debug_ind': int(get_data_entry_or(form_data, 'debugind', -1)),
'kbs_other': get_data_entry_or(form_data, 'kbs_other', None), 'kbs_other': get_data_entry_or(form_data, 'kbs_other', None),
} }
@ -107,6 +109,14 @@ def page_bid(self, url_split, post_string):
if len(data['addr_from_label']) > 0: if len(data['addr_from_label']) > 0:
data['addr_from_label'] = '(' + data['addr_from_label'] + ')' data['addr_from_label'] = '(' + data['addr_from_label'] + ')'
page_data = {
'bid_states': listBidStates(),
'bid_actions': []
}
if swap_client.debug_ui:
data['bid_actions'] = [(-1, 'None'), ] + listBidActions()
template = server.env.get_template('bid_xmr.html' if offer.swap_type == SwapTypes.XMR_SWAP else 'bid.html') template = server.env.get_template('bid_xmr.html' if offer.swap_type == SwapTypes.XMR_SWAP else 'bid.html')
return self.render_template(template, { return self.render_template(template, {
'bid_id': bid_id.hex(), 'bid_id': bid_id.hex(),
@ -175,9 +185,8 @@ def page_bids(self, url_split, post_string, sent=False, available=False, receive
bids = swap_client.listBids(sent=sent, filters=filters) bids = swap_client.listBids(sent=sent, filters=filters)
page_data = { page_data = {
'bid_states': listBidStates() 'bid_states': listBidStates(),
} }
template = server.env.get_template('bids.html') template = server.env.get_template('bids.html')
return self.render_template(template, { return self.render_template(template, {
'page_type_sent': 'Bids Sent' if sent else '', 'page_type_sent': 'Bids Sent' if sent else '',

@ -16,16 +16,17 @@ from basicswap.chainparams import (
chainparams, chainparams,
) )
from basicswap.basicswap_util import ( from basicswap.basicswap_util import (
TxTypes, ActionTypes,
TxStates,
BidStates, BidStates,
SwapTypes,
strTxType,
DebugTypes, DebugTypes,
strTxState, getLastBidState,
strBidState, strBidState,
strTxState,
strTxType,
SwapTypes,
TxLockTypes, TxLockTypes,
getLastBidState, TxStates,
TxTypes,
) )
from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey
@ -145,6 +146,13 @@ def listBidStates():
return rv return rv
def listBidActions():
rv = []
for a in ActionTypes:
rv.append((int(a), a.name))
return rv
def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_bid, show_txns, view_tx_ind=None, for_api=False, show_lock_transfers=False): def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_bid, show_txns, view_tx_ind=None, for_api=False, show_lock_transfers=False):
ci_from = swap_client.ci(Coins(offer.coin_from)) ci_from = swap_client.ci(Coins(offer.coin_from))
ci_to = swap_client.ci(Coins(offer.coin_to)) ci_to = swap_client.ci(Coins(offer.coin_to))

@ -8,11 +8,11 @@
import json import json
import time import time
from urllib.request import urlopen
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select from urllib.request import urlopen
from util import get_driver
from basicswap.util import dumpje from basicswap.util import dumpje
from util import get_driver
def test_wallets(driver): def test_wallets(driver):

Loading…
Cancel
Save