From d16e658a66a1443b367dba8ba8251c8961184681 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sun, 7 Jun 2026 19:17:24 +0200 Subject: [PATCH] fix: match Part address type used for funded itx and createSCLockTx --- basicswap/basicswap.py | 2 +- basicswap/protocols/atomic_swap_1.py | 10 +++++--- basicswap/protocols/xmr_swap_1.py | 37 ++++++++++++++++++++++++--- doc/release-notes.md | 1 + tests/basicswap/test_partblind_xmr.py | 4 +-- tests/basicswap/test_xmr.py | 4 +-- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 003f6e0..1bc38e7 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -6482,7 +6482,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp): xmr_swap.a_lock_tx = pi.promoteMockTx( ci_from, prefunded_tx, xmr_swap.a_lock_tx_script ) - self.log.info("Using pre-funded tx") + self.log.info(f"Using pre-funded {ci_from.ticker()} tx") else: xmr_swap.a_lock_tx = ci_from.createSCLockTx( bid.amount, xmr_swap.a_lock_tx_script, xmr_swap.vkbv diff --git a/basicswap/protocols/atomic_swap_1.py b/basicswap/protocols/atomic_swap_1.py index 3647778..4832cd3 100644 --- a/basicswap/protocols/atomic_swap_1.py +++ b/basicswap/protocols/atomic_swap_1.py @@ -139,13 +139,17 @@ class AtomicSwapInterface(ProtocolInterface): swap_type = SwapTypes.SELLER_FIRST def getFundedInitiateTxTemplate( - self, ci, amount: int, sub_fee: bool, feerate: int = None + self, + ci, + amount: int, + sub_fee: bool, + feerate: int = None, + lock_unspents: bool = False, ) -> bytes: addr_to = self.getMockScriptAddr(ci) funded_tx = ci.createRawFundedTransaction( - addr_to, amount, sub_fee, lock_unspents=False, feerate=feerate + addr_to, amount, sub_fee, lock_unspents=lock_unspents, feerate=feerate ) - return bytes.fromhex(funded_tx) def promoteMockTx(self, ci, mock_tx: bytes, script: bytearray) -> bytearray: diff --git a/basicswap/protocols/xmr_swap_1.py b/basicswap/protocols/xmr_swap_1.py index 0b32762..70086ec 100644 --- a/basicswap/protocols/xmr_swap_1.py +++ b/basicswap/protocols/xmr_swap_1.py @@ -221,8 +221,37 @@ class XmrSwapInterface(ProtocolInterface): return CScript([2, Kal, Kaf, 2, CScriptOp(OP_CHECKMULTISIG)]) + def getMockScriptAddr(self, ci): + script = self.getMockScript() + if ci.coin_type() == Coins.PART: + # Use btc-segwit address to match createSCLockTx() + # _use_segwit is false for Particl + return ci.encode_p2wsh(ci.getScriptDest(script)) + return ( + ci.encodeScriptDest(ci.getScriptDest(script)) + if ci._use_segwit + else ci.encode_p2sh(script) + ) + + def getMockScriptScriptPubkey(self, ci) -> bytearray: + script = self.getMockScript() + if ci.coin_type() == Coins.PART: + # Use btc-segwit address to match createSCLockTx() + # _use_segwit is false for Particl + return ci.getScriptDest(script) + return ( + ci.getScriptDest(script) + if ci._use_segwit + else ci.get_p2sh_script_pubkey(script) + ) + def getFundedInitiateTxTemplate( - self, ci, amount: int, sub_fee: bool, feerate: int = None + self, + ci, + amount: int, + sub_fee: bool, + feerate: int = None, + lock_unspents: bool = False, ) -> bytes: if ci.coin_type() == Coins.BCH: # Workaround, BCH getScriptDest() uses OP_HASH256 @@ -231,7 +260,7 @@ class XmrSwapInterface(ProtocolInterface): else: addr_to = self.getMockScriptAddr(ci) funded_tx = ci.createRawFundedTransaction( - addr_to, amount, sub_fee, lock_unspents=False, feerate=feerate + addr_to, amount, sub_fee, lock_unspents=lock_unspents, feerate=feerate ) return bytes.fromhex(funded_tx) @@ -275,7 +304,7 @@ class XmrSwapInterface(ProtocolInterface): raise ValueError("Too many mocked outputs found") ctx.nLockTime = 0 - return ctx.serialize_without_witness() + return ctx.serialize() def getMockPubkey(self, ci) -> bytes: return ci.getPubkey(self._mock_key) @@ -308,4 +337,4 @@ class XmrSwapInterface(ProtocolInterface): raise ValueError("swap output not found") tx_obj.vout[lock_vout].scriptPubKey = ci.getPkDest(Kbs) - return tx_obj.serialize_without_witness() + return tx_obj.serialize() diff --git a/doc/release-notes.md b/doc/release-notes.md index df4c3d3..e84bad8 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -23,6 +23,7 @@ - Added warning text for fee above 1.2 x local estimate. - Added subfee bid option. - Increase DCR fee estimate by 1 byte. +- Waits for the refund and refund spend txn locks to expire before trying to submit them. 0.14.5 diff --git a/tests/basicswap/test_partblind_xmr.py b/tests/basicswap/test_partblind_xmr.py index 70183d5..ff495b8 100644 --- a/tests/basicswap/test_partblind_xmr.py +++ b/tests/basicswap/test_partblind_xmr.py @@ -104,7 +104,7 @@ class Test(BaseTest): ) def test_010_txn_size(self): - logging.info("---------- Test {} txn_size".format(self.test_coin_from.name)) + logging.info(f"---------- Test {self.test_coin_from.name} txn_size") self.ensure_balance(self.test_coin_from, 0, 100.0) @@ -159,7 +159,7 @@ class Test(BaseTest): ci.rpc_wallet("sendrawtransaction", [lock_tx.hex()]) rv = ci.rpc_wallet("gettransaction", [txid]) - wallet_tx_fee = -ci.make_int(rv["details"][0]["fee"]) + wallet_tx_fee = -ci.make_int(rv["fee"]) assert wallet_tx_fee >= expect_fee_int assert wallet_tx_fee - expect_fee_int < 20 diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index 01f6bd7..271ceb8 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -2595,7 +2595,7 @@ class Test(BaseTest): swap_clients[2], bid_id, BidStates.SWAP_COMPLETED, - wait_for=120, + wait_for=180, ) wait_for_bid( test_delay_event, @@ -2603,7 +2603,7 @@ class Test(BaseTest): bid_id, BidStates.SWAP_COMPLETED, sent=True, - wait_for=120, + wait_for=180, ) # Verify expected inputs were used