diff --git a/basicswap/__init__.py b/basicswap/__init__.py index d2adcf2..2d5aca7 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.0.27" +__version__ = "0.0.28" diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index d130b77..5508b5b 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -101,9 +101,7 @@ import basicswap.config as cfg import basicswap.network as bsn import basicswap.protocols.atomic_swap_1 as atomic_swap_1 from .basicswap_util import ( - SEQUENCE_LOCK_TIME, - ABS_LOCK_BLOCKS, - ABS_LOCK_TIME, + TxLockTypes, AddressTypes, MessageTypes, SwapTypes, @@ -966,11 +964,11 @@ class BasicSwap(BaseApp): elif lock_type == OfferMessage.SEQUENCE_LOCK_BLOCKS: ensure(lock_value >= 5 and lock_value <= 1000, 'Invalid lock_value blocks') ensure(self.coin_clients[coin_from]['use_csv'] and self.coin_clients[coin_to]['use_csv'], 'Both coins need CSV activated.') - elif lock_type == ABS_LOCK_TIME: + elif lock_type == TxLockTypes.ABS_LOCK_TIME: # TODO: range? ensure(not self.coin_clients[coin_from]['use_csv'] or not self.coin_clients[coin_to]['use_csv'], 'Should use CSV.') ensure(lock_value >= 4 * 60 * 60 and lock_value <= 96 * 60 * 60, 'Invalid lock_value time') - elif lock_type == ABS_LOCK_BLOCKS: + elif lock_type == TxLockTypes.ABS_LOCK_BLOCKS: # TODO: range? ensure(not self.coin_clients[coin_from]['use_csv'] or not self.coin_clients[coin_to]['use_csv'], 'Should use CSV.') ensure(lock_value >= 10 and lock_value <= 1000, 'Invalid lock_value blocks') @@ -1005,7 +1003,7 @@ class BasicSwap(BaseApp): return self.network_addr def postOffer(self, coin_from, coin_to, amount, rate, min_bid_amount, swap_type, - lock_type=SEQUENCE_LOCK_TIME, lock_value=48 * 60 * 60, auto_accept_bids=False, addr_send_from=None, extra_options={}): + lock_type=TxLockTypes.SEQUENCE_LOCK_TIME, lock_value=48 * 60 * 60, auto_accept_bids=False, addr_send_from=None, extra_options={}): # Offer to send offer.amount_from of coin_from in exchange for offer.amount_from * offer.rate of coin_to ensure(coin_from != coin_to, 'coin_from == coin_to') @@ -1919,11 +1917,11 @@ class BasicSwap(BaseApp): txid = bid.initiate_tx.txid script = bid.initiate_tx.script else: - if offer.lock_type < ABS_LOCK_BLOCKS: + if offer.lock_type < TxLockTypes.ABS_LOCK_BLOCKS: sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value) script = atomic_swap_1.buildContractScript(sequence, secret_hash, bid.pkhash_buyer, pkhash_refund) else: - if offer.lock_type == ABS_LOCK_BLOCKS: + if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: lock_value = self.callcoinrpc(coin_from, 'getblockcount') + offer.lock_value else: lock_value = int(time.time()) + offer.lock_value @@ -2367,7 +2365,7 @@ class BasicSwap(BaseApp): # Participate txn is locked for half the time of the initiate txn lock_value = offer.lock_value // 2 - if offer.lock_type < ABS_LOCK_BLOCKS: + if offer.lock_type < TxLockTypes.ABS_LOCK_BLOCKS: sequence = ci_to.getExpectedSequence(offer.lock_type, lock_value) participate_script = atomic_swap_1.buildContractScript(sequence, secret_hash, pkhash_seller, pkhash_buyer_refund) else: @@ -2375,7 +2373,7 @@ class BasicSwap(BaseApp): coin_from = Coins(offer.coin_from) initiate_tx_block_hash = self.callcoinrpc(coin_from, 'getblockhash', [bid.initiate_tx.chain_height, ]) initiate_tx_block_time = int(self.callcoinrpc(coin_from, 'getblock', [initiate_tx_block_hash, ])['time']) - if offer.lock_type == ABS_LOCK_BLOCKS: + if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: # Walk the coin_to chain back until block time matches blockchaininfo = self.callcoinrpc(coin_to, 'getblockchaininfo') cblock_hash = blockchaininfo['bestblockhash'] @@ -2597,7 +2595,7 @@ class BasicSwap(BaseApp): 'amount': prev_amount} lock_value = DeserialiseNum(txn_script, 64) - if offer.lock_type < ABS_LOCK_BLOCKS: + if offer.lock_type < TxLockTypes.ABS_LOCK_BLOCKS: sequence = lock_value else: sequence = 1 @@ -2631,7 +2629,7 @@ class BasicSwap(BaseApp): else: refund_txn = self.calltx('-btcmode -create nversion=2' + prevout_s + output_to) - if offer.lock_type == ABS_LOCK_BLOCKS or offer.lock_type == ABS_LOCK_TIME: + if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS or offer.lock_type == TxLockTypes.ABS_LOCK_TIME: refund_txn = self.calltx('{} locktime={}'.format(refund_txn, lock_value)) options = {} @@ -3168,7 +3166,8 @@ class BasicSwap(BaseApp): addr = ci_to.encode_p2sh(bid.participate_tx.script) ci_to = self.ci(coin_to) - found = ci_to.getLockTxHeight(None, addr, bid.amount_to, bid.chain_b_height_start, find_index=True) + participate_txid = None if bid.participate_tx is None or bid.participate_tx.txid is None else bid.participate_tx.txid + found = ci_to.getLockTxHeight(participate_txid, addr, bid.amount_to, bid.chain_b_height_start, find_index=True) if found: if bid.participate_tx.conf != found['depth']: save_bid = True @@ -3224,8 +3223,9 @@ class BasicSwap(BaseApp): self.log.debug('Submitted initiate refund txn %s to %s chain for bid %s', txid, chainparams[coin_from]['name'], bid_id.hex()) # State will update when spend is detected except Exception as ex: - if 'non-BIP68-final (code 64)' not in str(ex) and 'non-final' not in str(ex): + if 'non-BIP68-final' not in str(ex) and 'non-final' not in str(ex): self.log.warning('Error trying to submit initiate refund txn: %s', str(ex)) + if (bid.getPTxState() == TxStates.TX_SENT or bid.getPTxState() == TxStates.TX_CONFIRMED) \ and bid.participate_txn_refund is not None: try: @@ -3233,7 +3233,7 @@ class BasicSwap(BaseApp): self.log.debug('Submitted participate refund txn %s to %s chain for bid %s', txid, chainparams[coin_to]['name'], bid_id.hex()) # State will update when spend is detected except Exception as ex: - if 'non-BIP68-final (code 64)' not in str(ex) and 'non-final' not in str(ex): + if 'non-BIP68-final' not in str(ex) and 'non-final' not in str(ex): self.log.warning('Error trying to submit participate refund txn: %s', str(ex)) return False # Bid is still active @@ -3905,7 +3905,7 @@ class BasicSwap(BaseApp): return raise ValueError('Wrong bid state: {}'.format(str(BidStates(bid.state)))) - use_csv = True if offer.lock_type < ABS_LOCK_BLOCKS else False + use_csv = True if offer.lock_type < TxLockTypes.ABS_LOCK_BLOCKS else False # TODO: Verify script without decoding? decoded_script = self.callcoinrpc(Coins.PART, 'decodescript', [bid_accept_data.contract_script.hex()]) @@ -3924,7 +3924,7 @@ class BasicSwap(BaseApp): expect_sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value) ensure(script_lock_value == expect_sequence, 'sequence mismatch') else: - if offer.lock_type == ABS_LOCK_BLOCKS: + if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: self.log.warning('TODO: validate absolute lock values') else: ensure(script_lock_value <= bid.created_at + offer.lock_value + atomic_swap_1.INITIATE_TX_TIMEOUT, 'script lock time too high') @@ -4938,6 +4938,14 @@ class BasicSwap(BaseApp): self.log.debug('Set state to %s', strBidState(bid.state)) has_changed = True + if bid.debug_ind != data['debug_ind']: + if bid.debug_ind is None and data['debug_ind'] == -1: + pass # Already unset + else: + self.log.debug('Bid %s Setting debug flag: %s', bid_id.hex(), data['debug_ind']) + bid.debug_ind = data['debug_ind'] + has_changed = True + if has_changed: session = scoped_session(self.session_factory) try: diff --git a/basicswap/basicswap_util.py b/basicswap/basicswap_util.py index 027e21b..4517392 100644 --- a/basicswap/basicswap_util.py +++ b/basicswap/basicswap_util.py @@ -17,10 +17,11 @@ from .chainparams import ( ) -SEQUENCE_LOCK_BLOCKS = 1 -SEQUENCE_LOCK_TIME = 2 -ABS_LOCK_BLOCKS = 3 -ABS_LOCK_TIME = 4 +class TxLockTypes(IntEnum): + SEQUENCE_LOCK_BLOCKS = 1 + SEQUENCE_LOCK_TIME = 2 + ABS_LOCK_BLOCKS = 3 + ABS_LOCK_TIME = 4 class MessageTypes(IntEnum): @@ -264,13 +265,13 @@ def strAddressType(addr_type): def getLockName(lock_type): - if lock_type == SEQUENCE_LOCK_BLOCKS: + if lock_type == TxLockTypes.SEQUENCE_LOCK_BLOCKS: return 'Sequence lock, blocks' - if lock_type == SEQUENCE_LOCK_TIME: + if lock_type == TxLockTypes.SEQUENCE_LOCK_TIME: return 'Sequence lock, time' - if lock_type == ABS_LOCK_BLOCKS: + if lock_type == TxLockTypes.ABS_LOCK_BLOCKS: return 'blocks' - if lock_type == ABS_LOCK_TIME: + if lock_type == TxLockTypes.ABS_LOCK_TIME: return 'time' diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 8d43df2..2751aa6 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -31,8 +31,7 @@ from .basicswap_util import ( strTxState, strAddressType, getLockName, - SEQUENCE_LOCK_TIME, - ABS_LOCK_TIME, + TxLockTypes, ) from .js_server import ( js_error, @@ -599,6 +598,9 @@ class HttpHandler(BaseHTTPRequestHandler): if have_data_entry(form_data, 'lockhrs'): page_data['lockhrs'] = int(get_data_entry(form_data, 'lockhrs')) parsed_data['lock_seconds'] = page_data['lockhrs'] * 60 * 60 + elif have_data_entry(form_data, 'lockmins'): + page_data['lockmins'] = int(get_data_entry(form_data, 'lockmins')) + parsed_data['lock_seconds'] = page_data['lockmins'] * 60 elif have_data_entry(form_data, 'lockseconds'): parsed_data['lock_seconds'] = int(get_data_entry(form_data, 'lockseconds')) @@ -651,9 +653,9 @@ class HttpHandler(BaseHTTPRequestHandler): swap_type = SwapTypes.XMR_SWAP if swap_client.coin_clients[parsed_data['coin_from']]['use_csv'] and swap_client.coin_clients[parsed_data['coin_to']]['use_csv']: - lock_type = SEQUENCE_LOCK_TIME + lock_type = TxLockTypes.SEQUENCE_LOCK_TIME else: - lock_type = ABS_LOCK_TIME + lock_type = TxLockTypes.ABS_LOCK_TIME extra_options = {} @@ -713,7 +715,9 @@ class HttpHandler(BaseHTTPRequestHandler): 'fee_to_conf': 2, 'validhrs': 1, 'lockhrs': 32, - 'autoaccept': True + 'lockmins': 30, # used in debug mode + 'autoaccept': True, + 'debug_ui': swap_client.debug_ui, } form_data = self.checkForm(post_string, 'newoffer', messages) @@ -740,6 +744,8 @@ class HttpHandler(BaseHTTPRequestHandler): else: template = env.get_template('offer_new_1.html') + if swap_client.debug_ui: + messages.append('Debug mode active.') coins_from, coins_to = listAvailableCoins(swap_client, split_from=True) return bytes(template.render( title=self.server.title, @@ -768,6 +774,8 @@ class HttpHandler(BaseHTTPRequestHandler): 'nb_validmins': 10, } messages = [] + if swap_client.debug_ui: + messages.append('Debug mode active.') sent_bid_id = None show_bid_form = None form_data = self.checkForm(post_string, 'offer', messages) @@ -851,6 +859,12 @@ class HttpHandler(BaseHTTPRequestHandler): } data.update(extend_data) + if offer.lock_type == TxLockTypes.SEQUENCE_LOCK_TIME or offer.lock_type == TxLockTypes.ABS_LOCK_TIME: + if offer.lock_value > 60 * 60: + data['lock_value_hr'] = ' ({} hours)'.format(offer.lock_value / (60 * 60)) + else: + data['lock_value_hr'] = ' ({} minutes)'.format(offer.lock_value / 60) + addr_from_label, addr_to_label = swap_client.getAddressLabel([offer.addr_from, offer.addr_to]) if len(addr_from_label) > 0: data['addr_from_label'] = '(' + addr_from_label + ')' @@ -988,7 +1002,8 @@ class HttpHandler(BaseHTTPRequestHandler): edit_bid = True elif b'edit_bid_submit' in form_data: data = { - 'bid_state': int(form_data[b'new_state'][0]) + 'bid_state': int(form_data[b'new_state'][0]), + 'debug_ind': int(get_data_entry_or(form_data, 'debugind', -1)) } try: swap_client.manualBidUpdate(bid_id, data) diff --git a/basicswap/interface_btc.py b/basicswap/interface_btc.py index 885ee99..7e8482f 100644 --- a/basicswap/interface_btc.py +++ b/basicswap/interface_btc.py @@ -63,8 +63,7 @@ from .contrib.test_framework.script import ( hash160) from .basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, - SEQUENCE_LOCK_TIME) + TxLockTypes) from .chainparams import CoinInterface, Coins from .rpc import make_rpc_func @@ -148,9 +147,9 @@ class BTCInterface(CoinInterface): @staticmethod def getExpectedSequence(lockType, lockVal): assert(lockVal >= 1), 'Bad lockVal' - if lockType == SEQUENCE_LOCK_BLOCKS: + if lockType == TxLockTypes.SEQUENCE_LOCK_BLOCKS: return lockVal - if lockType == SEQUENCE_LOCK_TIME: + if lockType == TxLockTypes.SEQUENCE_LOCK_TIME: secondsLocked = lockVal # Ensure the locked time is never less than lockVal if secondsLocked % (1 << SEQUENCE_LOCKTIME_GRANULARITY) != 0: @@ -954,8 +953,6 @@ class BTCInterface(CoinInterface): txns = self.rpc_callback('listunspent', [0, 9999999, [dest_address, ]]) for tx in txns: - print('bid_amount', bid_amount) - print('self.make_int(tx[amount])', self.make_int(tx['amount'])) if self.make_int(tx['amount']) == bid_amount: txid = bytes.fromhex(tx['txid']) break diff --git a/basicswap/templates/bid.html b/basicswap/templates/bid.html index c3f0c98..53f8f4d 100644 --- a/basicswap/templates/bid.html +++ b/basicswap/templates/bid.html @@ -50,6 +50,14 @@ {% endfor %} +{% if data.debug_ui == true %} +Debug Option +{% endif %} diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html index 169ac6a..5aadff0 100644 --- a/basicswap/templates/bid_xmr.html +++ b/basicswap/templates/bid_xmr.html @@ -43,6 +43,14 @@ {% endfor %} +{% if data.debug_ui == true %} +Debug Option +{% endif %} diff --git a/basicswap/templates/offer.html b/basicswap/templates/offer.html index f85fa1d..858b16e 100644 --- a/basicswap/templates/offer.html +++ b/basicswap/templates/offer.html @@ -23,7 +23,7 @@ Amount Variable{{ data.amount_negotiable }} Rate Variable{{ data.rate_negotiable }} Script Lock Type{{ data.lock_type }} -Script Lock Value{{ data.lock_value }} +Script Lock Value{{ data.lock_value }} {{ data.lock_value_hr }} {% if data.addr_to == "Public" %} Address To{{ data.addr_to }} {% else %} diff --git a/basicswap/templates/offer_confirm.html b/basicswap/templates/offer_confirm.html index 2e15401..0ba72e4 100644 --- a/basicswap/templates/offer_confirm.html +++ b/basicswap/templates/offer_confirm.html @@ -64,7 +64,11 @@ Rate Variable Offer valid (hrs) +{% if data.debug_ui == true %} +Contract locked (mins){% if data.swap_style != 'xmr' %}Participate txn will be locked for half the time.{% endif %} +{% else %} Contract locked (hrs){% if data.swap_style != 'xmr' %}Participate txn will be locked for half the time.{% endif %} +{% endif %} Auto Accept Bids diff --git a/basicswap/templates/offer_new_2.html b/basicswap/templates/offer_new_2.html index 3509437..f7fec5a 100644 --- a/basicswap/templates/offer_new_2.html +++ b/basicswap/templates/offer_new_2.html @@ -62,7 +62,11 @@ Offer valid (hrs) +{% if data.debug_ui == true %} +Contract locked (mins){% if data.swap_style != 'xmr' %}Participate txn will be locked for half the time.{% endif %} +{% else %} Contract locked (hrs){% if data.swap_style != 'xmr' %}Participate txn will be locked for half the time.{% endif %} +{% endif %} Auto Accept Bids diff --git a/basicswap/ui.py b/basicswap/ui.py index 5df0ab4..57a2601 100644 --- a/basicswap/ui.py +++ b/basicswap/ui.py @@ -13,7 +13,8 @@ from .chainparams import ( Coins, ) from .basicswap_util import ( - SEQUENCE_LOCK_TIME, + TxLockTypes, + DebugTypes, SwapTypes, BidStates, TxStates, @@ -192,7 +193,10 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b elif bid.state == BidStates.XMR_SWAP_HAVE_SCRIPT_COIN_SPEND_TX: state_description = f'Waiting for {ticker_from} lock tx to confirm in chain ({ci_from.blocks_confirmed} blocks)' elif bid.state == BidStates.XMR_SWAP_SCRIPT_COIN_LOCKED: - state_description = f'Waiting for {ticker_to} lock tx to confirm in chain ({ci_to.blocks_confirmed} blocks)' + if xmr_swap.b_lock_tx_id is None: + state_description = f'Waiting for {ticker_to} lock tx' + else: + state_description = f'Waiting for {ticker_to} lock tx to confirm in chain ({ci_to.blocks_confirmed} blocks)' elif bid.state == BidStates.XMR_SWAP_NOSCRIPT_COIN_LOCKED: state_description = f'Waiting for offerer to unlock {ticker_from} lock tx' elif bid.state == BidStates.XMR_SWAP_LOCK_RELEASED: @@ -203,13 +207,14 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b state_description = f'Waiting for {ticker_to} lock tx spend tx to confirm in chain' addr_label = swap_client.getAddressLabel([bid.bid_addr, ])[0] + bid_rate = offer.rate if bid.rate is None else bid.rate data = { 'coin_from': ci_from.coin_name(), 'coin_to': ci_to.coin_name(), 'amt_from': ci_from.format_amount(bid.amount), - 'amt_to': ci_to.format_amount((bid.amount * bid.rate) // ci_from.COIN()), - 'bid_rate': ci_to.format_amount(bid.rate), + 'amt_to': ci_to.format_amount((bid.amount * bid_rate) // ci_from.COIN()), + 'bid_rate': ci_to.format_amount(bid_rate), 'ticker_from': ticker_from, 'ticker_to': ticker_to, 'bid_state': strBidState(bid.state), @@ -231,12 +236,17 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b 'show_txns': show_txns, 'can_abandon': True if bid.state not in (BidStates.BID_ABANDONED, BidStates.SWAP_COMPLETED) else False, 'events': bid_events, + 'debug_ui': swap_client.debug_ui, } if edit_bid: data['bid_state_ind'] = int(bid.state) data['bid_states'] = listBidStates() + if swap_client.debug_ui: + data['debug_ind'] = bid.debug_ind + data['debug_options'] = [(int(t), t.name) for t in DebugTypes] + if show_txns: if offer.swap_type == SwapTypes.XMR_SWAP: txns = [] @@ -285,7 +295,7 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b if offer.swap_type == SwapTypes.XMR_SWAP: data['coin_a_lock_refund_tx_est_final'] = 'None' if bid.xmr_a_lock_tx and bid.xmr_a_lock_tx.block_time: - if offer.lock_type == SEQUENCE_LOCK_TIME: + if offer.lock_type == TxLockTypes.SEQUENCE_LOCK_TIME: raw_sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value) seconds_locked = ci_from.decodeSequence(raw_sequence) data['coin_a_lock_refund_tx_est_final'] = bid.xmr_a_lock_tx.block_time + seconds_locked diff --git a/tests/basicswap/test_btc_xmr.py b/tests/basicswap/test_btc_xmr.py index 96b69b2..aab623e 100644 --- a/tests/basicswap/test_btc_xmr.py +++ b/tests/basicswap/test_btc_xmr.py @@ -18,7 +18,7 @@ from basicswap.basicswap import ( DebugTypes, ) from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, + TxLockTypes, ) from basicswap.util import ( make_int, @@ -117,7 +117,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -152,7 +152,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -194,7 +194,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=18) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=18) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) diff --git a/tests/basicswap/test_ltc_xmr.py b/tests/basicswap/test_ltc_xmr.py index 6a41a87..0447f5b 100644 --- a/tests/basicswap/test_ltc_xmr.py +++ b/tests/basicswap/test_ltc_xmr.py @@ -18,7 +18,7 @@ from basicswap.basicswap import ( DebugTypes, ) from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, + TxLockTypes, ) from basicswap.util import ( make_int, @@ -138,7 +138,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -173,7 +173,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -214,7 +214,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( self.test_coin_from, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=18) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=18) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) diff --git a/tests/basicswap/test_other.py b/tests/basicswap/test_other.py index a9a89f1..d97f74c 100644 --- a/tests/basicswap/test_other.py +++ b/tests/basicswap/test_other.py @@ -26,8 +26,7 @@ from basicswap.interface_btc import BTCInterface from basicswap.interface_xmr import XMRInterface from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, - SEQUENCE_LOCK_TIME) + TxLockTypes) from basicswap.util import ( make_int, SerialiseNum, @@ -59,19 +58,19 @@ class Test(unittest.TestCase): ci = BTCInterface(coin_settings, 'regtest') time_val = 48 * 60 * 60 - encoded = ci.getExpectedSequence(SEQUENCE_LOCK_TIME, time_val) + encoded = ci.getExpectedSequence(TxLockTypes.SEQUENCE_LOCK_TIME, time_val) decoded = ci.decodeSequence(encoded) assert(decoded >= time_val) assert(decoded <= time_val + 512) time_val = 24 * 60 - encoded = ci.getExpectedSequence(SEQUENCE_LOCK_TIME, time_val) + encoded = ci.getExpectedSequence(TxLockTypes.SEQUENCE_LOCK_TIME, time_val) decoded = ci.decodeSequence(encoded) assert(decoded >= time_val) assert(decoded <= time_val + 512) blocks_val = 123 - encoded = ci.getExpectedSequence(SEQUENCE_LOCK_BLOCKS, blocks_val) + encoded = ci.getExpectedSequence(TxLockTypes.SEQUENCE_LOCK_BLOCKS, blocks_val) decoded = ci.decodeSequence(encoded) assert(decoded == blocks_val) diff --git a/tests/basicswap/test_partblind_xmr.py b/tests/basicswap/test_partblind_xmr.py index 6e89616..f3ce796 100644 --- a/tests/basicswap/test_partblind_xmr.py +++ b/tests/basicswap/test_partblind_xmr.py @@ -18,7 +18,7 @@ from basicswap.basicswap import ( DebugTypes, ) from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, + TxLockTypes, ) from basicswap.util import ( make_int, @@ -127,7 +127,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( Coins.PART_BLIND, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -160,7 +160,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( Coins.PART_BLIND, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -201,7 +201,7 @@ class Test(BaseTest): rate_swap = make_int(random.uniform(0.2, 20.0), scale=12, r=1) offer_id = swap_clients[0].postOffer( Coins.PART_BLIND, Coins.XMR, amt_swap, rate_swap, amt_swap, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=18) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=18) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) diff --git a/tests/basicswap/test_run.py b/tests/basicswap/test_run.py index dfdba71..67f6701 100644 --- a/tests/basicswap/test_run.py +++ b/tests/basicswap/test_run.py @@ -27,7 +27,7 @@ from basicswap.basicswap import ( DebugTypes, ) from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, + TxLockTypes, ) from basicswap.util import ( COIN, @@ -193,7 +193,7 @@ class Test(BaseTest): swap_clients = self.swap_clients offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST, - SEQUENCE_LOCK_BLOCKS, 10) + TxLockTypes.SEQUENCE_LOCK_BLOCKS, 10) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -294,7 +294,7 @@ class Test(BaseTest): swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1) logging.info('swap_value {}'.format(format_amount(swap_value, 8))) offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, swap_value, 0.1 * COIN, swap_value, SwapTypes.SELLER_FIRST, - SEQUENCE_LOCK_BLOCKS, 10) + TxLockTypes.SEQUENCE_LOCK_BLOCKS, 10) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -326,7 +326,7 @@ class Test(BaseTest): swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1) logging.info('swap_value {}'.format(format_amount(swap_value, 8))) offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, swap_value, 0.1 * COIN, swap_value, SwapTypes.SELLER_FIRST, - SEQUENCE_LOCK_BLOCKS, 10) + TxLockTypes.SEQUENCE_LOCK_BLOCKS, 10) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -377,7 +377,7 @@ class Test(BaseTest): swap_value = make_int(random.uniform(2.0, 20.0), scale=8, r=1) logging.info('swap_value {}'.format(format_amount(swap_value, 8))) offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, swap_value, 0.5 * COIN, swap_value, SwapTypes.SELLER_FIRST, - SEQUENCE_LOCK_BLOCKS, 10) + TxLockTypes.SEQUENCE_LOCK_BLOCKS, 10) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index 4960e71..e1c3006 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -27,7 +27,7 @@ from basicswap.basicswap import ( DebugTypes, ) from basicswap.basicswap_util import ( - SEQUENCE_LOCK_BLOCKS, + TxLockTypes, ) from basicswap.util import ( COIN, @@ -660,7 +660,7 @@ class Test(BaseTest): offer_id = swap_clients[0].postOffer( Coins.PART, Coins.XMR, 101 * COIN, 0.12 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -688,7 +688,7 @@ class Test(BaseTest): offer_id = swap_clients[0].postOffer( Coins.PART, Coins.XMR, 101 * COIN, 0.13 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=12) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id) @@ -719,7 +719,7 @@ class Test(BaseTest): offer_id = swap_clients[0].postOffer( Coins.PART, Coins.XMR, 101 * COIN, 0.14 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP, - lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=18) + lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=18) wait_for_offer(test_delay_event, swap_clients[1], offer_id) offer = swap_clients[1].getOffer(offer_id)