mirror of
https://github.com/basicswap/basicswap.git
synced 2026-02-28 08:35:09 +01:00
Compare commits
1 Commits
0e092ad7e9
...
revert-409
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d454d76d6f |
@@ -1,3 +1,3 @@
|
||||
name = "basicswap"
|
||||
|
||||
__version__ = "0.15.2"
|
||||
__version__ = "0.15.1"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2024 tecnovert
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -1919,15 +1919,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.activateBid(cursor, bid)
|
||||
except Exception as ex:
|
||||
self.logException(f"Failed to activate bid! Error: {ex}")
|
||||
self.logEvent(
|
||||
Concepts.BID,
|
||||
bid.bid_id,
|
||||
EventLogTypes.ERROR,
|
||||
"Failed to activate",
|
||||
cursor,
|
||||
)
|
||||
try:
|
||||
bid.setState(BidStates.BID_ERROR)
|
||||
bid.setState(BidStates.BID_ERROR, "Failed to activate")
|
||||
|
||||
offer = self.queryOne(
|
||||
Offer, cursor, {"offer_id": bid.offer_id}
|
||||
@@ -3201,13 +3194,12 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
raise ValueError("Must specify offer for save_in_progress")
|
||||
self.swaps_in_progress[bid_id] = (bid, save_in_progress) # (bid, offer)
|
||||
|
||||
def saveBid(self, bid_id: bytes, bid, xmr_swap=None, cursor=None) -> None:
|
||||
def saveBid(self, bid_id: bytes, bid, xmr_swap=None) -> None:
|
||||
cursor = self.openDB()
|
||||
try:
|
||||
use_cursor = self.openDB(cursor)
|
||||
self.saveBidInSession(bid_id, bid, use_cursor, xmr_swap)
|
||||
self.saveBidInSession(bid_id, bid, cursor, xmr_swap)
|
||||
finally:
|
||||
if cursor is None:
|
||||
self.closeDB(use_cursor)
|
||||
self.closeDB(cursor)
|
||||
|
||||
def createActionInSession(
|
||||
self, delay: int, action_type: int, linked_id: bytes, cursor
|
||||
@@ -3271,20 +3263,17 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.log.debug(f"logBidEvent {self.log.id(bid_id)} {event_type}")
|
||||
self.logEvent(Concepts.BID, bid_id, event_type, event_msg, cursor)
|
||||
|
||||
def countEvents(self, linked_type: int, linked_id: bytes, event_type: int, cursor):
|
||||
def countBidEvents(self, bid, event_type, cursor):
|
||||
q = cursor.execute(
|
||||
"SELECT COUNT(*) FROM eventlog WHERE linked_type = :linked_type AND linked_id = :linked_id AND event_type = :event_type",
|
||||
{
|
||||
"linked_type": int(Concepts.BID),
|
||||
"linked_id": linked_id,
|
||||
"linked_id": bid.bid_id,
|
||||
"event_type": int(event_type),
|
||||
},
|
||||
).fetchone()
|
||||
return q[0]
|
||||
|
||||
def countBidEvents(self, bid, event_type: int, cursor):
|
||||
return self.countEvents(int(Concepts.BID), bid.bid_id, int(event_type))
|
||||
|
||||
def getEvents(self, linked_type: int, linked_id: bytes):
|
||||
events = []
|
||||
cursor = self.openDB()
|
||||
@@ -3859,7 +3848,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
|
||||
txid = ci_from.publishTx(bytes.fromhex(txn))
|
||||
self.log.debug(
|
||||
f"Submitted initiate txn {self.logIDT(txid)} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}",
|
||||
f"Submitted initiate txn {txid} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}",
|
||||
)
|
||||
bid.initiate_tx = SwapTx(
|
||||
bid_id=bid_id,
|
||||
@@ -5013,18 +5002,13 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.deactivateBidForReason(bid_id, BidStates.SWAP_TIMEDOUT, cursor=cursor)
|
||||
|
||||
def setBidError(
|
||||
self,
|
||||
bid,
|
||||
error_str: str,
|
||||
save_bid: bool = True,
|
||||
xmr_swap=None,
|
||||
cursor=None,
|
||||
self, bid_id: bytes, bid, error_str: str, save_bid: bool = True, xmr_swap=None
|
||||
) -> None:
|
||||
self.log.error(f"Bid {self.log.id(bid.bid_id)} - Error: {error_str}")
|
||||
self.logEvent(Concepts.BID, bid.bid_id, EventLogTypes.ERROR, error_str, cursor)
|
||||
self.log.error(f"Bid {self.log.id(bid_id)} - Error: {error_str}")
|
||||
bid.setState(BidStates.BID_ERROR)
|
||||
bid.state_note = "error msg: " + error_str
|
||||
if save_bid:
|
||||
self.saveBid(bid.bid_id, bid, xmr_swap=xmr_swap, cursor=cursor)
|
||||
self.saveBid(bid_id, bid, xmr_swap=xmr_swap)
|
||||
|
||||
def createInitiateTxn(
|
||||
self, coin_type, bid_id: bytes, bid, initiate_script, prefunded_tx=None
|
||||
@@ -5530,7 +5514,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
txn = self.createParticipateTxn(bid_id, bid, offer, participate_script)
|
||||
txid = ci_to.publishTx(bytes.fromhex(txn))
|
||||
self.log.debug(
|
||||
f"Submitted participate tx {self.logIDT(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}"
|
||||
f"Submitted participate tx {self.log.id(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}"
|
||||
)
|
||||
bid.setPTxState(TxStates.TX_SENT)
|
||||
self.logEvent(
|
||||
@@ -5638,7 +5622,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
txn = self.createRedeemTxn(ci_to.coin_type(), bid)
|
||||
txid = ci_to.publishTx(bytes.fromhex(txn))
|
||||
self.log.debug(
|
||||
f"Submitted participate redeem tx {self.logIDT(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted participate redeem tx {self.log.id(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logEvent(
|
||||
Concepts.BID, bid.bid_id, EventLogTypes.PTX_REDEEM_PUBLISHED, "", None
|
||||
@@ -5924,7 +5908,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
|
||||
self.log.info(
|
||||
f"Submitted coin a lock refund spend tx for bid {self.log.id(bid_id)}, txid {self.logIDT(txid_str)}"
|
||||
f"Submitted coin a lock refund spend tx for bid {self.log.id(bid_id)}, txid {self.log.id(txid_str)}"
|
||||
)
|
||||
bid.txns[TxTypes.XMR_SWAP_A_LOCK_REFUND_SPEND] = SwapTx(
|
||||
bid_id=bid_id,
|
||||
@@ -5999,7 +5983,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
txid=bytes.fromhex(txid_hex),
|
||||
)
|
||||
self.log.info(
|
||||
f"Submitted mercy tx for bid {self.log.id(bid_id)}, txid {self.logIDT(txid_hex)}"
|
||||
f"Submitted mercy tx for bid {self.log.id(bid_id)}, txid {self.log.id(txid_hex)}"
|
||||
)
|
||||
self.logBidEvent(
|
||||
bid_id,
|
||||
@@ -6686,7 +6670,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
try:
|
||||
txid = ci_to.publishTx(bid.participate_txn_refund)
|
||||
self.log.debug(
|
||||
f"Submitted participate refund txn {self.logIDT(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted participate refund txn {self.log.id(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logEvent(
|
||||
Concepts.BID,
|
||||
@@ -6742,7 +6726,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
def removeWatchedTransaction(self, coin_type, bid_id: bytes, txid_hex: str) -> None:
|
||||
# Remove all for bid if txid is None
|
||||
self.log.debug(
|
||||
f"Removing watched transaction {Coins(coin_type).name} {self.log.id(bid_id)} {self.logIDT(txid_hex)}"
|
||||
f"Removing watched transaction {Coins(coin_type).name} {self.log.id(bid_id)} {self.log.id(txid_hex)}"
|
||||
)
|
||||
watched = self.coin_clients[coin_type]["watched_transactions"]
|
||||
old_len = len(watched)
|
||||
@@ -6751,7 +6735,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
if wo.bid_id == bid_id and (txid_hex is None or wo.txid_hex == txid_hex):
|
||||
del watched[i]
|
||||
self.log.debug(
|
||||
f"Removed watched transaction {Coins(coin_type).name} {self.log.id(bid_id)} {self.logIDT(wo.txid_hex)}"
|
||||
f"Removed watched transaction {Coins(coin_type).name} {self.log.id(bid_id)} {self.log.id(wo.txid_hex)}"
|
||||
)
|
||||
|
||||
def addWatchedOutput(
|
||||
@@ -6772,7 +6756,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
def removeWatchedOutput(self, coin_type, bid_id: bytes, txid_hex: str) -> None:
|
||||
# Remove all for bid if txid is None
|
||||
self.log.debug(
|
||||
f"Removing watched output {Coins(coin_type).name} {self.log.id(bid_id)} {self.logIDT(txid_hex)}"
|
||||
f"Removing watched output {Coins(coin_type).name} {self.log.id(bid_id)} {self.log.id(txid_hex)}"
|
||||
)
|
||||
watched = self.coin_clients[coin_type]["watched_outputs"]
|
||||
old_len = len(watched)
|
||||
@@ -6781,7 +6765,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
if wo.bid_id == bid_id and (txid_hex is None or wo.txid_hex == txid_hex):
|
||||
del watched[i]
|
||||
self.log.debug(
|
||||
f"Removed watched output {Coins(coin_type).name} {self.log.id(bid_id)} {self.logIDT(wo.txid_hex)}"
|
||||
f"Removed watched output {Coins(coin_type).name} {self.log.id(bid_id)} {self.log.id(wo.txid_hex)}"
|
||||
)
|
||||
|
||||
def addWatchedScript(
|
||||
@@ -7032,10 +7016,10 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
else:
|
||||
self.setBidError(
|
||||
bid.bid_id,
|
||||
bid,
|
||||
"Unexpected txn spent coin a lock tx: {}".format(spend_txid_hex),
|
||||
save_bid=False,
|
||||
cursor=use_cursor,
|
||||
)
|
||||
|
||||
self.saveBidInSession(
|
||||
@@ -7745,11 +7729,12 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.logException(err_msg)
|
||||
|
||||
bid_id = linked_id
|
||||
# Failing to accept a bid should not set an error state as the bid has not begun yet
|
||||
if accepting_bid:
|
||||
self.logEvent(
|
||||
Concepts.BID, bid_id, EventLogTypes.ERROR, err_msg, cursor
|
||||
)
|
||||
# Failing to accept a bid should not set an error state as the bid has not begun yet
|
||||
if accepting_bid:
|
||||
|
||||
# If delaying with no (further) queued actions reset state
|
||||
if self.countQueuedActions(cursor, bid_id, None) < 2:
|
||||
bid, offer = self.getBidAndOffer(bid_id, cursor)
|
||||
@@ -7769,7 +7754,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
else:
|
||||
bid = self.getBid(bid_id, cursor)
|
||||
if bid:
|
||||
bid.setState(BidStates.BID_ERROR)
|
||||
bid.setState(BidStates.BID_ERROR, err_msg)
|
||||
self.saveBidInSession(bid_id, bid, cursor)
|
||||
|
||||
query: str = "DELETE FROM actions WHERE trigger_at <= :now"
|
||||
@@ -7860,14 +7845,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.log.debug(
|
||||
f"Expiring partially received {bid_type}: {self.log.id(bid.bid_id)}."
|
||||
)
|
||||
self.logEvent(
|
||||
Concepts.BID,
|
||||
bid.bid_id,
|
||||
EventLogTypes.ERROR,
|
||||
"Timed out (partially received bid)",
|
||||
cursor,
|
||||
)
|
||||
bid.setState(BidStates.BID_ERROR)
|
||||
bid.setState(BidStates.BID_ERROR, "Timed out")
|
||||
self.updateDB(
|
||||
bid,
|
||||
cursor,
|
||||
@@ -9155,7 +9133,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
except Exception as ex:
|
||||
if self.debug:
|
||||
self.log.error(traceback.format_exc())
|
||||
self.setBidError(bid, str(ex), xmr_swap=xmr_swap)
|
||||
self.setBidError(bid.bid_id, bid, str(ex), xmr_swap=xmr_swap)
|
||||
|
||||
def watchXmrSwap(self, bid, offer, xmr_swap, cursor=None) -> None:
|
||||
self.log.debug(f"Adaptor-sig swap in progress, bid {self.log.id(bid.bid_id)}.")
|
||||
@@ -9430,7 +9408,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
xmr_swap.a_lock_tx, xmr_swap.a_lock_tx_script
|
||||
)
|
||||
self.log.debug(
|
||||
f"Submitted lock tx {self.logIDT(txid_hex)} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}.",
|
||||
f"Submitted lock tx {self.log.id(txid_hex)} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}.",
|
||||
)
|
||||
|
||||
if bid.xmr_a_lock_tx is None:
|
||||
@@ -9499,7 +9477,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.saveBidInSession(bid_id, bid, cursor, xmr_swap, save_in_progress=offer)
|
||||
return
|
||||
|
||||
unlock_time: int = 0
|
||||
unlock_time = 0
|
||||
if bid.debug_ind in (
|
||||
DebugTypes.CREATE_INVALID_COIN_B_LOCK,
|
||||
DebugTypes.B_LOCK_TX_MISSED_SEND,
|
||||
@@ -9570,10 +9548,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
else:
|
||||
self.setBidError(
|
||||
bid,
|
||||
"publishBLockTx failed: " + str(ex),
|
||||
save_bid=False,
|
||||
cursor=cursor,
|
||||
bid_id, bid, "publishBLockTx failed: " + str(ex), save_bid=False
|
||||
)
|
||||
self.saveBidInSession(
|
||||
bid_id, bid, cursor, xmr_swap, save_in_progress=offer
|
||||
@@ -9585,7 +9560,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
return
|
||||
|
||||
self.log.debug(
|
||||
f"Submitted lock txn {self.logIDT(b_lock_tx_id)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted lock txn {self.log.id(bid_id)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
bid.xmr_b_lock_tx = SwapTx(
|
||||
bid_id=bid_id,
|
||||
@@ -9597,7 +9572,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_B_PUBLISHED, "", cursor)
|
||||
if bid.debug_ind == DebugTypes.BID_STOP_AFTER_COIN_B_LOCK:
|
||||
self.log.debug(
|
||||
f"Adaptor-sig bid {self.log.id(bid_id)}: Stalling bid for testing: {bid.debug_ind}."
|
||||
"Adaptor-sig bid {self.log.id(bid_id)}: Stalling bid for testing: {bid.debug_ind}."
|
||||
)
|
||||
bid.setState(BidStates.BID_STALLED_FOR_TEST)
|
||||
self.logBidEvent(
|
||||
@@ -9758,7 +9733,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
|
||||
txid = bytes.fromhex(ci_from.publishTx(xmr_swap.a_lock_spend_tx))
|
||||
self.log.debug(
|
||||
f"Submitted lock spend txn {self.logIDT(txid)} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted lock spend txn {self.log.id(txid)} to {ci_from.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logBidEvent(
|
||||
bid.bid_id, EventLogTypes.LOCK_TX_A_SPEND_TX_PUBLISHED, "", cursor
|
||||
@@ -9868,7 +9843,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
lock_tx_vout=lock_tx_vout,
|
||||
)
|
||||
self.log.debug(
|
||||
f"Submitted lock B spend txn {self.logIDT(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted lock B spend txn {self.log.id(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logBidEvent(
|
||||
bid.bid_id, EventLogTypes.LOCK_TX_B_SPEND_TX_PUBLISHED, "", cursor
|
||||
@@ -9896,10 +9871,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
else:
|
||||
self.setBidError(
|
||||
bid,
|
||||
"spendBLockTx failed: " + str(ex),
|
||||
save_bid=False,
|
||||
cursor=cursor,
|
||||
bid_id, bid, "spendBLockTx failed: " + str(ex), save_bid=False
|
||||
)
|
||||
self.saveBidInSession(
|
||||
bid_id, bid, cursor, xmr_swap, save_in_progress=offer
|
||||
@@ -9986,7 +9958,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
),
|
||||
)
|
||||
self.log.debug(
|
||||
f"Submitted lock B refund txn {self.logIDT(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted lock B refund txn {self.log.id(txid)} to {ci_to.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logBidEvent(
|
||||
bid.bid_id, EventLogTypes.LOCK_TX_B_REFUND_TX_PUBLISHED, "", cursor
|
||||
@@ -10014,10 +9986,10 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
else:
|
||||
self.setBidError(
|
||||
bid_id,
|
||||
bid,
|
||||
"spendBLockTx for refund failed: " + str(ex),
|
||||
save_bid=False,
|
||||
cursor=cursor,
|
||||
)
|
||||
self.saveBidInSession(
|
||||
bid_id, bid, cursor, xmr_swap, save_in_progress=offer
|
||||
@@ -10218,7 +10190,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
except Exception as ex:
|
||||
if self.debug:
|
||||
self.log.error(traceback.format_exc())
|
||||
self.setBidError(bid, str(ex))
|
||||
self.setBidError(bid_id, bid, str(ex))
|
||||
|
||||
def processXmrBidLockSpendTx(self, msg) -> None:
|
||||
# Follower receiving MSG4F
|
||||
@@ -10283,7 +10255,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
except Exception as ex:
|
||||
if self.debug:
|
||||
self.log.error(traceback.format_exc())
|
||||
self.setBidError(bid, str(ex))
|
||||
self.setBidError(bid_id, bid, str(ex))
|
||||
|
||||
# Update copy of bid in swaps_in_progress
|
||||
self.swaps_in_progress[bid_id] = (bid, offer)
|
||||
@@ -10385,7 +10357,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
except Exception as ex:
|
||||
if self.debug:
|
||||
self.log.error(traceback.format_exc())
|
||||
self.setBidError(bid, str(ex))
|
||||
self.setBidError(bid_id, bid, str(ex))
|
||||
self.swaps_in_progress[bid_id] = (bid, offer)
|
||||
return
|
||||
|
||||
@@ -10998,10 +10970,9 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
to_remove = []
|
||||
if now - self._last_checked_progress >= self.check_progress_seconds:
|
||||
for bid_id, v in self.swaps_in_progress.items():
|
||||
bid, offer = v
|
||||
try:
|
||||
if self.checkBidState(bid_id, bid, offer) is True:
|
||||
to_remove.append((bid_id, bid, offer))
|
||||
if self.checkBidState(bid_id, v[0], v[1]) is True:
|
||||
to_remove.append((bid_id, v[0], v[1]))
|
||||
except Exception as ex:
|
||||
if self.debug:
|
||||
self.log.error("checkBidState %s", traceback.format_exc())
|
||||
@@ -11017,7 +10988,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
)
|
||||
else:
|
||||
self.log.error(f"checkBidState {self.log.id(bid_id)} {ex}.")
|
||||
self.setBidError(bid, str(ex))
|
||||
self.setBidError(bid_id, v[0], str(ex))
|
||||
|
||||
for bid_id, bid, offer in to_remove:
|
||||
self.deactivateBid(None, offer, bid)
|
||||
|
||||
@@ -55,13 +55,13 @@ PARTICL_VERSION = os.getenv("PARTICL_VERSION", "27.2.3.0")
|
||||
PARTICL_VERSION_TAG = os.getenv("PARTICL_VERSION_TAG", "")
|
||||
PARTICL_LINUX_EXTRA = os.getenv("PARTICL_LINUX_EXTRA", "nousb")
|
||||
|
||||
BITCOIN_VERSION = os.getenv("BITCOIN_VERSION", "29.2")
|
||||
BITCOIN_VERSION = os.getenv("BITCOIN_VERSION", "28.0")
|
||||
BITCOIN_VERSION_TAG = os.getenv("BITCOIN_VERSION_TAG", "")
|
||||
|
||||
LITECOIN_VERSION = os.getenv("LITECOIN_VERSION", "0.21.4")
|
||||
LITECOIN_VERSION_TAG = os.getenv("LITECOIN_VERSION_TAG", "")
|
||||
|
||||
DCR_VERSION = os.getenv("DCR_VERSION", "2.1.2")
|
||||
DCR_VERSION = os.getenv("DCR_VERSION", "1.8.1")
|
||||
DCR_VERSION_TAG = os.getenv("DCR_VERSION_TAG", "")
|
||||
|
||||
NMC_VERSION = os.getenv("NMC_VERSION", "28.0")
|
||||
|
||||
@@ -242,7 +242,7 @@ chainparams = {
|
||||
"pubkey_address": 0x0E91,
|
||||
"script_address": 0x0E6C,
|
||||
"key_prefix": 0x2307,
|
||||
"bip44": 115,
|
||||
"bip44": 1,
|
||||
"min_amount": 100000,
|
||||
"max_amount": 10000000 * COIN,
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2024 tecnovert
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -13,7 +13,7 @@ from enum import IntEnum, auto
|
||||
from typing import Optional
|
||||
|
||||
|
||||
CURRENT_DB_VERSION = 33
|
||||
CURRENT_DB_VERSION = 32
|
||||
CURRENT_DB_DATA_VERSION = 7
|
||||
|
||||
|
||||
@@ -76,16 +76,10 @@ class Table:
|
||||
__sqlite3_table__ = True
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
init_all_columns: bool = True
|
||||
for name, value in kwargs.items():
|
||||
if name == "_init_all_columns":
|
||||
init_all_columns = value
|
||||
continue
|
||||
if not hasattr(self, name):
|
||||
raise ValueError(f"Unknown attribute {name}")
|
||||
setattr(self, name, value)
|
||||
if init_all_columns is False:
|
||||
return
|
||||
# Init any unset columns to None
|
||||
for mc in inspect.getmembers(self):
|
||||
mc_name, mc_obj = mc
|
||||
@@ -141,20 +135,6 @@ class Index:
|
||||
self.column_3 = column_3
|
||||
|
||||
|
||||
class StateRows:
|
||||
state = Column("integer")
|
||||
state_time = Column("integer") # Timestamp of last state change
|
||||
states = Column("blob") # Packed states and times
|
||||
|
||||
def setState(self, new_state, state_time=None):
|
||||
now = int(time.time()) if state_time is None else state_time
|
||||
self.state = new_state
|
||||
if self.isSet("states") is False:
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class DBKVInt(Table):
|
||||
__tablename__ = "kv_int"
|
||||
|
||||
@@ -169,7 +149,7 @@ class DBKVString(Table):
|
||||
value = Column("string")
|
||||
|
||||
|
||||
class Offer(Table, StateRows):
|
||||
class Offer(Table):
|
||||
__tablename__ = "offers"
|
||||
|
||||
offer_id = Column("blob", primary_key=True)
|
||||
@@ -217,8 +197,19 @@ class Offer(Table, StateRows):
|
||||
bid_reversed = Column("bool")
|
||||
smsg_payload_version = Column("integer")
|
||||
|
||||
state = Column("integer")
|
||||
states = Column("blob") # Packed states and times
|
||||
|
||||
class Bid(Table, StateRows):
|
||||
def setState(self, new_state):
|
||||
now = int(time.time())
|
||||
self.state = new_state
|
||||
if self.isSet("states") is False:
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class Bid(Table):
|
||||
__tablename__ = "bids"
|
||||
|
||||
bid_id = Column("blob", primary_key=True)
|
||||
@@ -253,7 +244,11 @@ class Bid(Table, StateRows):
|
||||
participate_txn_refund = Column("blob")
|
||||
|
||||
in_progress = Column("integer")
|
||||
state = Column("integer")
|
||||
state_time = Column("integer") # Timestamp of last state change
|
||||
states = Column("blob") # Packed states and times
|
||||
|
||||
state_note = Column("string")
|
||||
was_sent = Column("bool") # Sent by node
|
||||
was_received = Column("bool")
|
||||
contract_count = Column("integer")
|
||||
@@ -292,13 +287,25 @@ class Bid(Table, StateRows):
|
||||
if self.isSet("participate_tx"):
|
||||
self.participate_tx.setState(new_state)
|
||||
|
||||
def setState(self, new_state, state_note=None):
|
||||
now = int(time.time())
|
||||
self.state = new_state
|
||||
self.state_time = now
|
||||
|
||||
if self.isSet("state_note"):
|
||||
self.state_note = state_note
|
||||
if self.isSet("states") is False:
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
def getLockTXBVout(self):
|
||||
if self.isSet("xmr_b_lock_tx"):
|
||||
return self.xmr_b_lock_tx.vout
|
||||
return None
|
||||
|
||||
|
||||
class SwapTx(Table, StateRows):
|
||||
class SwapTx(Table):
|
||||
__tablename__ = "transactions"
|
||||
|
||||
bid_id = Column("blob")
|
||||
@@ -321,8 +328,21 @@ class SwapTx(Table, StateRows):
|
||||
block_height = Column("integer")
|
||||
block_time = Column("integer")
|
||||
|
||||
state = Column("integer")
|
||||
states = Column("blob") # Packed states and times
|
||||
|
||||
primary_key = PrimaryKeyConstraint("bid_id", "tx_type")
|
||||
|
||||
def setState(self, new_state):
|
||||
if self.state == new_state:
|
||||
return
|
||||
self.state = new_state
|
||||
now: int = int(time.time())
|
||||
if self.isSet("states") is False:
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class PrefundedTx(Table):
|
||||
__tablename__ = "prefunded_transactions"
|
||||
@@ -1039,7 +1059,7 @@ class DBMethods:
|
||||
if cursor is None:
|
||||
self.closeDB(use_cursor, commit=False)
|
||||
|
||||
def add(self, obj, cursor, upsert: bool = False, columns_list=None):
|
||||
def add(self, obj, cursor, upsert: bool = False):
|
||||
if cursor is None:
|
||||
raise ValueError("Cursor is null")
|
||||
if not hasattr(obj, "__tablename__"):
|
||||
@@ -1052,8 +1072,7 @@ class DBMethods:
|
||||
# See if the instance overwrote any class methods
|
||||
for mc in inspect.getmembers(obj.__class__):
|
||||
mc_name, mc_obj = mc
|
||||
if columns_list is not None and mc_name not in columns_list:
|
||||
continue
|
||||
|
||||
if not hasattr(mc_obj, "__sqlite3_column__"):
|
||||
continue
|
||||
|
||||
@@ -1094,7 +1113,6 @@ class DBMethods:
|
||||
order_by={},
|
||||
query_suffix=None,
|
||||
extra_query_data={},
|
||||
columns_list=None,
|
||||
):
|
||||
if cursor is None:
|
||||
raise ValueError("Cursor is null")
|
||||
@@ -1107,8 +1125,6 @@ class DBMethods:
|
||||
|
||||
for mc in inspect.getmembers(table_class):
|
||||
mc_name, mc_obj = mc
|
||||
if columns_list is not None and mc_name not in columns_list:
|
||||
continue
|
||||
if not hasattr(mc_obj, "__sqlite3_column__"):
|
||||
continue
|
||||
if len(columns) > 0:
|
||||
@@ -1177,7 +1193,6 @@ class DBMethods:
|
||||
order_by={},
|
||||
query_suffix=None,
|
||||
extra_query_data={},
|
||||
columns_list=None,
|
||||
):
|
||||
return firstOrNone(
|
||||
self.query(
|
||||
@@ -1187,11 +1202,10 @@ class DBMethods:
|
||||
order_by,
|
||||
query_suffix,
|
||||
extra_query_data,
|
||||
columns_list,
|
||||
)
|
||||
)
|
||||
|
||||
def updateDB(self, obj, cursor, constraints=[], columns_list=None):
|
||||
def updateDB(self, obj, cursor, constraints=[]):
|
||||
if cursor is None:
|
||||
raise ValueError("Cursor is null")
|
||||
if not hasattr(obj, "__tablename__"):
|
||||
@@ -1203,6 +1217,7 @@ class DBMethods:
|
||||
values = {}
|
||||
for mc in inspect.getmembers(obj.__class__):
|
||||
mc_name, mc_obj = mc
|
||||
|
||||
if not hasattr(mc_obj, "__sqlite3_column__"):
|
||||
continue
|
||||
|
||||
@@ -1214,8 +1229,7 @@ class DBMethods:
|
||||
if mc_name in constraints:
|
||||
values[mc_name] = m_obj
|
||||
continue
|
||||
if columns_list is not None and mc_name not in columns_list:
|
||||
continue
|
||||
|
||||
if len(values) > 0:
|
||||
query += ", "
|
||||
query += f"{mc_name} = :{mc_name}"
|
||||
|
||||
@@ -406,9 +406,6 @@ class DCRInterface(Secp256k1Interface):
|
||||
# Adjust verificationprogress to consider blocks wallet has synced
|
||||
wallet_blocks = self.rpc_wallet("getinfo")["blocks"]
|
||||
synced_ind = bci["verificationprogress"]
|
||||
if bci["headers"] < 1:
|
||||
wallet_synced_ind = 0
|
||||
else:
|
||||
wallet_synced_ind = wallet_blocks / bci["headers"]
|
||||
if wallet_synced_ind < synced_ind:
|
||||
bci["verificationprogress"] = wallet_synced_ind
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2024 tecnovert
|
||||
# Copyright (c) 2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -36,13 +35,6 @@ def createDCRWallet(args, hex_seed, logging, delay_event):
|
||||
response = b"y\n"
|
||||
elif "Enter existing wallet seed" in buf:
|
||||
response = (hex_seed + "\n").encode("utf-8")
|
||||
elif "Do you have a wallet birthday we should rescan from" in buf:
|
||||
response = b"no\n"
|
||||
elif (
|
||||
"Do you have an additional account to import from an extended public key"
|
||||
in buf
|
||||
):
|
||||
response = b"no\n"
|
||||
elif "Seed input successful" in buf:
|
||||
pass
|
||||
elif "Upgrading database from version" in buf:
|
||||
|
||||
@@ -130,7 +130,10 @@ def redeemITx(self, bid_id: bytes, cursor):
|
||||
|
||||
bid.initiate_tx.spend_txid = bytes.fromhex(txid)
|
||||
self.log.debug(
|
||||
f"Submitted initiate redeem txn {self.logIDT(txid)} to {ci_from.coin_name()} chain for bid {self.logIDB(bid_id)}"
|
||||
"Submitted initiate redeem txn %s to %s chain for bid %s",
|
||||
txid,
|
||||
ci_from.coin_name(),
|
||||
bid_id.hex(),
|
||||
)
|
||||
self.logEvent(Concepts.BID, bid_id, EventLogTypes.ITX_REDEEM_PUBLISHED, "", cursor)
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key, cursor=None):
|
||||
lock_tx_vout=lock_tx_vout,
|
||||
)
|
||||
self.log.debug(
|
||||
f"Submitted lock B spend txn {self.logIDT(txid)} to {ci_follower.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
f"Submitted lock B spend txn {self.log.id(txid)} to {ci_follower.coin_name()} chain for bid {self.log.id(bid_id)}."
|
||||
)
|
||||
self.logBidEvent(
|
||||
bid.bid_id,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2024 tecnovert
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -251,7 +251,7 @@ def describeBid(
|
||||
elif bid.state == BidStates.BID_ABANDONED:
|
||||
state_description = "Bid abandoned"
|
||||
elif bid.state == BidStates.BID_ERROR:
|
||||
state_description = "Bid error"
|
||||
state_description = bid.state_note
|
||||
elif offer.swap_type == SwapTypes.XMR_SWAP:
|
||||
if bid.state == BidStates.BID_SENT:
|
||||
state_description = "Waiting for offerer to accept"
|
||||
|
||||
10
guix.scm
10
guix.scm
@@ -90,7 +90,7 @@
|
||||
(define python-coincurve-basicswap
|
||||
(package
|
||||
(name "python-coincurve-basicswap")
|
||||
(version "basicswap_v0.3")
|
||||
(version "basicswap_v0.2")
|
||||
(source
|
||||
(origin
|
||||
(method git-fetch)
|
||||
@@ -101,7 +101,7 @@
|
||||
(file-name
|
||||
(git-file-name name version))
|
||||
(sha256
|
||||
(base32 "08bc8175v4d479lgavkcclc0kkh3icxm9i0i26wqd1g3bv0is8cm"))))
|
||||
(base32 "1vm9cvwr0z02zc0mp7l8qj9vhg8kmfrzysiwzg91zkgmccza9ryc"))))
|
||||
(build-system pyproject-build-system)
|
||||
(arguments
|
||||
`(#:phases
|
||||
@@ -135,15 +135,15 @@
|
||||
(define-public basicswap
|
||||
(package
|
||||
(name "basicswap")
|
||||
(version "0.15.2")
|
||||
(version "0.15.1")
|
||||
(source (origin
|
||||
(method git-fetch)
|
||||
(uri (git-reference
|
||||
(url "https://github.com/basicswap/basicswap")
|
||||
(commit "2259e964b11925587301070f9fc15e2226b2eb69")))
|
||||
(commit "0bc9d3a5db40f54d79e2ab18be58b6bbc20740d1")))
|
||||
(sha256
|
||||
(base32
|
||||
"0d544bj4kvra9y6rpqai1yvnk2igxj4z8s14g5jpksx5z9l0nyy3"))
|
||||
"1x6c6hynvbayq4cyv9s6vwgsgdmhm7r1av6iy7pax103lj20habf"))
|
||||
(file-name (git-file-name name version))))
|
||||
(build-system pyproject-build-system)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pyzmq==27.1.0
|
||||
python-gnupg==0.5.6
|
||||
python-gnupg==0.5.5
|
||||
Jinja2==3.1.6
|
||||
pycryptodome==3.23.0
|
||||
PySocks==1.7.1
|
||||
|
||||
@@ -122,9 +122,9 @@ pysocks==1.7.1 \
|
||||
--hash=sha256:2725bd0a9925919b9b51739eea5f9e2bae91e83288108a9ad338b2e3a4435ee5 \
|
||||
--hash=sha256:3f8804571ebe159c380ac6de37643bb4685970655d3bba243530d6558b799aa0
|
||||
# via -r requirements.in
|
||||
python-gnupg==0.5.6 \
|
||||
--hash=sha256:5743e96212d38923fc19083812dc127907e44dbd3bcf0db4d657e291d3c21eac \
|
||||
--hash=sha256:b5050a55663d8ab9fcc8d97556d229af337a87a3ebebd7054cbd8b7e2043394a
|
||||
python-gnupg==0.5.5 \
|
||||
--hash=sha256:3fdcaf76f60a1b948ff8e37dc398d03cf9ce7427065d583082b92da7a4ff5a63 \
|
||||
--hash=sha256:51fa7b8831ff0914bc73d74c59b99c613de7247b91294323c39733bb85ac3fc1
|
||||
# via -r requirements.in
|
||||
pyzmq==27.1.0 \
|
||||
--hash=sha256:01c0e07d558b06a60773744ea6251f769cd79a41a97d11b8bf4ab8f034b0424d \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2024 tecnovert
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -689,7 +689,7 @@ def prepareDCDDataDir(datadir, node_id, conf_file, dir_prefix, num_nodes=3):
|
||||
"noseeders=1\n",
|
||||
"nodnsseed=1\n",
|
||||
"nodiscoverip=1\n",
|
||||
"miningaddr=SsppG7KLiH52NC7iJmUVGVq89FLS83E5vho\n",
|
||||
"miningaddr=SsYbXyjkKAEXXcGdFgr4u4bo4L8RkCxwQpH\n",
|
||||
]
|
||||
|
||||
for i in range(0, num_nodes):
|
||||
@@ -725,8 +725,7 @@ class Test(BaseTest):
|
||||
dcr_daemons = []
|
||||
start_ltc_nodes = False
|
||||
start_xmr_nodes = True
|
||||
# Addresses differ after 2.1.2, simnet bip44id changed from 1 to 115
|
||||
dcr_mining_addr = "SsppG7KLiH52NC7iJmUVGVq89FLS83E5vho"
|
||||
dcr_mining_addr = "SsYbXyjkKAEXXcGdFgr4u4bo4L8RkCxwQpH"
|
||||
extra_wait_time = 0
|
||||
max_fee: int = 10000
|
||||
|
||||
@@ -740,8 +739,7 @@ class Test(BaseTest):
|
||||
def prepareExtraCoins(cls):
|
||||
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
||||
if not cls.restore_instance:
|
||||
dcr_mining_addr = ci0.rpc_wallet("getnewaddress")
|
||||
assert dcr_mining_addr in cls.dcr_mining_addrs
|
||||
assert ci0.rpc_wallet("getnewaddress") == cls.dcr_mining_addr
|
||||
cls.dcr_ticket_account = ci0.rpc_wallet(
|
||||
"getaccount",
|
||||
[
|
||||
@@ -778,7 +776,7 @@ class Test(BaseTest):
|
||||
num_passed: int = 0
|
||||
for i in range(30):
|
||||
try:
|
||||
ci0.rpc_wallet("purchaseticket", [cls.dcr_ticket_account, 0, 1])
|
||||
ci0.rpc_wallet("purchaseticket", [cls.dcr_ticket_account, 0.1, 0])
|
||||
num_passed += 1
|
||||
if num_passed >= 5:
|
||||
break
|
||||
@@ -904,14 +902,14 @@ class Test(BaseTest):
|
||||
masterpubkey = loop_ci.rpc_wallet("getmasterpubkey")
|
||||
masterpubkey_data = loop_ci.decode_address(masterpubkey)[4:]
|
||||
|
||||
seed_hash: bytes = loop_ci.getSeedHash(root_key)
|
||||
seed_hash = loop_ci.getSeedHash(root_key)
|
||||
if i == 0:
|
||||
assert (
|
||||
masterpubkey
|
||||
== "spubVUjNdu1HtDuQYHjVLTgdK3JKtC7JQoCUkhkoVn3rJt6kYctRksn4vTGsdV3obeZLHaB1YobsLENYKHjtey67LFZJdjJyAvHuRqgFRpaSmfn"
|
||||
== "spubVV1z2AFYjVZvzM45FSaWMPRqyUoUwyW78wfANdjdNG6JGCXrr8AbRvUgYb3Lm1iun9CgHew1KswdePryNLKEnBSQ82AjNpYdQgzXPUme9c6"
|
||||
)
|
||||
if i < 2:
|
||||
assert hash160(masterpubkey_data) == seed_hash
|
||||
assert seed_hash == hash160(masterpubkey_data)
|
||||
|
||||
def test_001_segwit(self):
|
||||
logging.info("---------- Test {} segwit".format(self.test_coin.name))
|
||||
|
||||
@@ -663,7 +663,6 @@ class Test(unittest.TestCase):
|
||||
ki.record_id = 1
|
||||
ki.address = "test1"
|
||||
ki.label = "test1"
|
||||
ki.note = "note1"
|
||||
try:
|
||||
db_test.add(ki, cursor, upsert=False)
|
||||
except Exception as e:
|
||||
@@ -671,65 +670,6 @@ class Test(unittest.TestCase):
|
||||
else:
|
||||
raise ValueError("Should have errored.")
|
||||
db_test.add(ki, cursor, upsert=True)
|
||||
|
||||
# Test columns list
|
||||
ki_test = db_test.queryOne(
|
||||
KnownIdentity,
|
||||
cursor,
|
||||
{"address": "test1"},
|
||||
columns_list=[
|
||||
"label",
|
||||
],
|
||||
)
|
||||
assert ki_test.label == "test1"
|
||||
assert ki_test.address is None
|
||||
|
||||
# Test updating partial row
|
||||
ki_test.label = "test2"
|
||||
ki_test.record_id = 1
|
||||
db_test.add(
|
||||
ki_test,
|
||||
cursor,
|
||||
upsert=True,
|
||||
columns_list=[
|
||||
"record_id",
|
||||
"label",
|
||||
],
|
||||
)
|
||||
ki_test = db_test.queryOne(KnownIdentity, cursor, {"address": "test1"})
|
||||
assert ki_test.record_id == 1
|
||||
assert ki_test.address == "test1"
|
||||
assert ki_test.label == "test2"
|
||||
assert ki_test.note == "note1"
|
||||
|
||||
ki_test.note = "test2"
|
||||
ki_test.label = "test3"
|
||||
|
||||
db_test.updateDB(
|
||||
ki_test,
|
||||
cursor,
|
||||
["record_id"],
|
||||
columns_list=[
|
||||
"label",
|
||||
],
|
||||
)
|
||||
ki_test = db_test.queryOne(KnownIdentity, cursor, {"address": "test1"})
|
||||
assert ki_test.record_id == 1
|
||||
assert ki_test.address == "test1"
|
||||
assert ki_test.label == "test3"
|
||||
assert ki_test.note == "note1"
|
||||
|
||||
# Test partially initialised object
|
||||
ki_test_p = KnownIdentity(
|
||||
_init_all_columns=False, record_id=1, label="test4"
|
||||
)
|
||||
db_test.add(ki_test_p, cursor, upsert=True)
|
||||
ki_test = db_test.queryOne(KnownIdentity, cursor, {"address": "test1"})
|
||||
assert ki_test.record_id == 1
|
||||
assert ki_test.address == "test1"
|
||||
assert ki_test.label == "test4"
|
||||
assert ki_test.note == "note1"
|
||||
|
||||
finally:
|
||||
db_test.closeDB(cursor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user