diff --git a/basicswap/__init__.py b/basicswap/__init__.py index af2ffe5..5218d44 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.11.64" +__version__ = "0.11.65" diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 636f2cc..ad8808e 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2068,8 +2068,8 @@ class BasicSwap(BaseApp): def countMessageLinks(self, linked_type: int, linked_id: int, msg_type: int, msg_sequence: int = 0, session=None) -> int: try: use_session = self.openSession(session) - q = session.execute('SELECT COUNT(*) FROM message_links WHERE linked_type = :linked_type AND linked_id = :linked_id AND msg_type = :msg_type AND msg_sequence = :msg_sequence', - {'linked_type': linked_type, 'linked_id': linked_id, 'msg_type': msg_type, 'msg_sequence': msg_sequence}).first() + q = use_session.execute('SELECT COUNT(*) FROM message_links WHERE linked_type = :linked_type AND linked_id = :linked_id AND msg_type = :msg_type AND msg_sequence = :msg_sequence', + {'linked_type': linked_type, 'linked_id': linked_id, 'msg_type': msg_type, 'msg_sequence': msg_sequence}).first() return q[0] finally: if session is None: diff --git a/basicswap/db.py b/basicswap/db.py index 8d79708..3a57aa6 100644 --- a/basicswap/db.py +++ b/basicswap/db.py @@ -13,7 +13,7 @@ from sqlalchemy.ext.declarative import declarative_base CURRENT_DB_VERSION = 21 -CURRENT_DB_DATA_VERSION = 3 +CURRENT_DB_DATA_VERSION = 4 Base = declarative_base() diff --git a/basicswap/db_upgrades.py b/basicswap/db_upgrades.py index d9619fb..7a2c4b0 100644 --- a/basicswap/db_upgrades.py +++ b/basicswap/db_upgrades.py @@ -80,6 +80,17 @@ def upgradeDatabaseData(self, data_version): 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)}) + if data_version > 0 and data_version < 4: + for state in (BidStates.BID_REQUEST_SENT, ): + session.add(BidState( + 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)) self.db_data_version = CURRENT_DB_DATA_VERSION self.setIntKVInSession('db_data_version', self.db_data_version, session) diff --git a/basicswap/protocols/xmr_swap_1.py b/basicswap/protocols/xmr_swap_1.py index a727e8c..1a2592a 100644 --- a/basicswap/protocols/xmr_swap_1.py +++ b/basicswap/protocols/xmr_swap_1.py @@ -86,27 +86,28 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key): def getChainBSplitKey(swap_client, bid, xmr_swap, offer): - ci_to = swap_client.ci(offer.coin_to) + reverse_bid: bool = offer.bid_reversed + ci_follower = swap_client.ci(offer.coin_from if reverse_bid else offer.coin_to) key_type = KeyTypes.KBSF if bid.was_sent else KeyTypes.KBSL - return ci_to.encodeKey(swap_client.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, key_type, True if offer.coin_to == Coins.XMR else False)) + return ci_follower.encodeKey(swap_client.getPathKey(offer.coin_from, offer.coin_to, bid.created_at, xmr_swap.contract_count, key_type, True if ci_follower.coin_type() == Coins.XMR else False)) def getChainBRemoteSplitKey(swap_client, bid, xmr_swap, offer): - ci_from = swap_client.ci(offer.coin_from) - ci_to = swap_client.ci(offer.coin_to) + reverse_bid: bool = offer.bid_reversed + ci_leader = swap_client.ci(offer.coin_to if reverse_bid else offer.coin_from) + ci_follower = swap_client.ci(offer.coin_from if reverse_bid else offer.coin_to) if bid.was_sent: if xmr_swap.a_lock_refund_spend_tx: - af_lock_refund_spend_tx_sig = ci_from.extractFollowerSig(xmr_swap.a_lock_refund_spend_tx) - kbsl = ci_from.recoverEncKey(xmr_swap.af_lock_refund_spend_tx_esig, af_lock_refund_spend_tx_sig, xmr_swap.pkasl) - return ci_to.encodeKey(kbsl) + af_lock_refund_spend_tx_sig = ci_leader.extractFollowerSig(xmr_swap.a_lock_refund_spend_tx) + kbsl = ci_leader.recoverEncKey(xmr_swap.af_lock_refund_spend_tx_esig, af_lock_refund_spend_tx_sig, xmr_swap.pkasl) + return ci_follower.encodeKey(kbsl) else: if xmr_swap.a_lock_spend_tx: - al_lock_spend_tx_sig = ci_from.extractLeaderSig(xmr_swap.a_lock_spend_tx) - kbsf = ci_from.recoverEncKey(xmr_swap.al_lock_spend_tx_esig, al_lock_spend_tx_sig, xmr_swap.pkasf) - return ci_to.encodeKey(kbsf) - + al_lock_spend_tx_sig = ci_leader.extractLeaderSig(xmr_swap.a_lock_spend_tx) + kbsf = ci_leader.recoverEncKey(xmr_swap.al_lock_spend_tx_esig, al_lock_spend_tx_sig, xmr_swap.pkasf) + return ci_follower.encodeKey(kbsf) return None diff --git a/basicswap/ui/util.py b/basicswap/ui/util.py index bc5c083..f9e2ba7 100644 --- a/basicswap/ui/util.py +++ b/basicswap/ui/util.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020-2022 tecnovert +# Copyright (c) 2020-2023 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php.