diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index a7a059f..871e658 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -198,6 +198,7 @@ class BasicSwap(BaseApp): self.check_events_seconds = self.settings.get('check_events_seconds', 10) self.check_xmr_swaps_seconds = self.settings.get('check_xmr_swaps_seconds', 20) self.startup_tries = self.settings.get('startup_tries', 21) # Seconds waited for will be (x(1 + x+1) / 2 + self.debug_ui = self.settings.get('debug_ui', False) self._last_checked_progress = 0 self._last_checked_watched = 0 self._last_checked_expired = 0 diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 9685426..d92090e 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -25,6 +25,7 @@ from .chainparams import ( ) from .basicswap_util import ( SwapTypes, + DebugTypes, strOfferState, strBidState, strTxState, @@ -55,6 +56,7 @@ from .ui import ( setCoinFilter, get_data_entry, have_data_entry, + get_data_entry_or, ) @@ -759,6 +761,7 @@ class HttpHandler(BaseHTTPRequestHandler): ci_from = swap_client.ci(Coins(offer.coin_from)) ci_to = swap_client.ci(Coins(offer.coin_to)) + debugind = -1 # Set defaults bid_amount = ci_from.format_amount(offer.amount_from) @@ -795,9 +798,15 @@ class HttpHandler(BaseHTTPRequestHandler): amount_from = inputAmount(bid_amount, ci_from) else: amount_from = offer.amount_from + debugind = int(get_data_entry_or(form_data, 'debugind', -1)) sent_bid_id = swap_client.postBid(offer_id, amount_from, addr_send_from=addr_from, extra_options=extra_options).hex() + + if debugind > -1: + swap_client.setBidDebugInd(bytes.fromhex(sent_bid_id), debugind) except Exception as ex: + if self.server.swap_client.debug is True: + traceback.print_exc() messages.append('Error: Send bid failed: ' + str(ex)) show_bid_form = True @@ -825,9 +834,14 @@ class HttpHandler(BaseHTTPRequestHandler): 'rate_negotiable': offer.rate_negotiable, 'bid_amount': bid_amount, 'bid_rate': bid_rate, + 'debug_ui': swap_client.debug_ui, } data.update(extend_data) + if swap_client.debug_ui: + data['debug_ind'] = debugind + data['debug_options'] = [(int(t), t.name) for t in DebugTypes] + if xmr_offer: int_fee_rate_now, fee_source = ci_from.get_fee_rate() data['xmr_type'] = True @@ -975,7 +989,7 @@ class HttpHandler(BaseHTTPRequestHandler): data = describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, events, edit_bid, show_txns, view_tx_ind, show_lock_transfers=show_lock_transfers) if bid.debug_ind is not None and bid.debug_ind > 0: - messages.append('Debug flag set: {}'.format(bid.debug_ind)) + messages.append('Debug flag set: {}, {}'.format(bid.debug_ind, DebugTypes(bid.debug_ind).name)) old_states = [] num_states = len(bid.states) // 12 diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 07403db..0b3c63c 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -186,6 +186,11 @@ def js_bids(self, url_split, post_string, is_json): extra_options = { 'valid_for_seconds': valid_for_seconds, } + if have_data_entry(form_data, 'bid_rate'): + extra_options['bid_rate'] = ci_to.make_int(get_data_entry(form_data, 'bid_rate'), r=1) + if have_data_entry(form_data, 'bid_amount'): + amount_from = inputAmount(get_data_entry(form_data, 'bid_amount'), ci_from) + if offer.swap_type == SwapTypes.XMR_SWAP: bid_id = swap_client.postXmrBid(offer_id, amount_from, addr_send_from=addr_from, extra_options=extra_options) else: @@ -258,7 +263,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json): post_data = urllib.parse.parse_qs(post_string) if url_split[3] == 'new': addressnote = get_data_entry_or(post_data, 'addressnote', '') - new_addr, pubkey = swap_client.newSMSGAddress(addressnote) + new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote) return bytes(json.dumps({'new_address': new_addr, 'pubkey': pubkey}), 'UTF-8') if url_split[3] == 'add': addressnote = get_data_entry_or(post_data, 'addressnote', '') diff --git a/basicswap/templates/offer.html b/basicswap/templates/offer.html index b7aa839..bd51bee 100644 --- a/basicswap/templates/offer.html +++ b/basicswap/templates/offer.html @@ -69,6 +69,14 @@ {% endif %} Minutes valid +{% if data.debug_ui == true %} +Debug Option +{% endif %} diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index fd4f0e2..784f770 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -188,7 +188,6 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey, with_l 'bindir': cfg.BITCOIN_BINDIR, 'use_segwit': True, } - }, 'check_progress_seconds': 2, 'check_watched_seconds': 4, @@ -198,7 +197,8 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey, with_l 'min_delay_event': 1, 'max_delay_event': 5, 'min_delay_retry': 2, - 'max_delay_retry': 10 + 'max_delay_retry': 10, + 'debug_ui': True, } if with_ltc: