Fix getLinkedMessageId and validateSwapType

2024-05-20_merge
tecnovert 1 year ago
parent a13a5d4bf6
commit 8f4b962285
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 2
      basicswap/__init__.py
  2. 16
      basicswap/basicswap.py
  3. 21
      doc/release-notes.md
  4. 6
      tests/basicswap/test_btc_xmr.py
  5. 25
      tests/basicswap/test_run.py

@ -1,3 +1,3 @@
name = "basicswap"
__version__ = "0.11.65"
__version__ = "0.11.66"

@ -266,7 +266,7 @@ class BasicSwap(BaseApp):
# TODO: Set dynamically
self.scriptless_coins = (Coins.XMR, Coins.PART_ANON)
self.adaptor_swap_only_coins = self.scriptless_coins + (Coins.PART_BLIND, )
self.secret_hash_swap_only_coins = (Coins.PIVX, Coins.DASH, Coins.FIRO, Coins.NMC)
self.secret_hash_swap_only_coins = (Coins.PIVX, Coins.DASH, Coins.FIRO, Coins.NMC) # Coins without segwit
# TODO: Adjust ranges
self.min_delay_event = self.settings.get('min_delay_event', 10)
@ -1145,14 +1145,16 @@ class BasicSwap(BaseApp):
return bytes.fromhex(ro['msgid'])
def validateSwapType(self, coin_from, coin_to, swap_type):
if (coin_from in self.adaptor_swap_only_coins or coin_to in self.adaptor_swap_only_coins) and swap_type != SwapTypes.XMR_SWAP:
raise ValueError('Invalid swap type for: {} -> {}'.format(coin_from.name, coin_to.name))
if swap_type == SwapTypes.XMR_SWAP:
if (coin_from in self.secret_hash_swap_only_coins or coin_to in self.secret_hash_swap_only_coins):
reverse_bid: bool = coin_from in self.scriptless_coins
itx_coin = coin_to if reverse_bid else coin_from
if (itx_coin in self.secret_hash_swap_only_coins):
raise ValueError('Invalid swap type for: {} -> {}'.format(coin_from.name, coin_to.name))
if (coin_from in self.scriptless_coins and coin_to in self.scriptless_coins):
raise ValueError('Invalid swap type for: {} -> {}'.format(coin_from.name, coin_to.name))
else:
if coin_from in self.adaptor_swap_only_coins or coin_to in self.adaptor_swap_only_coins:
raise ValueError('Invalid swap type for: {} -> {}'.format(coin_from.name, coin_to.name))
def notify(self, event_type, event_data, session=None) -> None:
show_event = event_type not in self._disabled_notification_types
@ -2066,8 +2068,8 @@ class BasicSwap(BaseApp):
def getLinkedMessageId(self, linked_type: int, linked_id: int, msg_type: int, msg_sequence: int = 0, session=None) -> bytes:
try:
use_session = self.openSession(session)
q = session.execute('SELECT msg_id 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 msg_id 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:

@ -1,18 +1,29 @@
0.0.64
0.0.66
==============
- Fixed bugs in getLinkedMessageId and validateSwapType.
0.0.65
==============
- protocol: Added reversed Adaptor sig protocol.
- Runs the adaptor-sig protocol with leader and follower swapped to
enable offers from no-script coins to script coins.
- smsg: Outbox messages are removed when expired.
- Fixed BTC witness size estimation.
- Added option to remove Offers and bids from the database automatically one week
after they expire if they have no active bids.
- Controlled by new settings: expire_db_records and expire_db_records_after
- ui: Show ITX and PTX status for adaptor sig type swaps.
0.0.64
==============
- protocol: Added reversed Adaptor sig protocol.
- Runs the adaptor-sig protocol with leader and follower swapped to
enable offers from no-script coins to script coins.
- Raised adaptor signature swap protocol version
- Not backwards compatible with previous versions.
- ui: Show ITX and PTX status for adaptor sig type swaps.
0.0.63

@ -506,9 +506,10 @@ class BasicSwapTest(TestFunctions):
tx_spend_hex = ToHex(tx_spend)
try:
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
assert False, 'Should fail'
except Exception as e:
assert ('non-final' in str(e))
else:
assert False, 'Should fail'
self.mineBlock(5)
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
@ -551,9 +552,10 @@ class BasicSwapTest(TestFunctions):
tx_spend_hex = ToHex(tx_spend)
try:
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
assert False, 'Should fail'
except Exception as e:
assert ('non-BIP68-final' in str(e))
else:
assert False, 'Should fail'
self.mineBlock(3)
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])

@ -166,6 +166,31 @@ class Test(BaseTest):
rv = read_json_api(1800, 'automationstrategies/1')
assert (rv['label'] == 'Accept All')
def test_004_validateSwapType(self):
logging.info('---------- Test validateSwapType')
sc = self.swap_clients[0]
should_pass = [
(Coins.BTC, Coins.XMR, SwapTypes.XMR_SWAP),
(Coins.XMR, Coins.BTC, SwapTypes.XMR_SWAP),
(Coins.BTC, Coins.FIRO, SwapTypes.XMR_SWAP),
(Coins.FIRO, Coins.BTC, SwapTypes.SELLER_FIRST),
(Coins.BTC, Coins.FIRO, SwapTypes.SELLER_FIRST),
]
should_fail = [
(Coins.BTC, Coins.XMR, SwapTypes.SELLER_FIRST),
(Coins.FIRO, Coins.BTC, SwapTypes.XMR_SWAP),
(Coins.XMR, Coins.PART_ANON, SwapTypes.XMR_SWAP),
(Coins.FIRO, Coins.PART_ANON, SwapTypes.XMR_SWAP),
(Coins.PART_ANON, Coins.FIRO, SwapTypes.XMR_SWAP),
]
for case in should_pass:
sc.validateSwapType(case[0], case[1], case[2])
for case in should_fail:
self.assertRaises(ValueError, sc.validateSwapType, case[0], case[1], case[2])
def test_01_verifyrawtransaction(self):
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
prevout = {

Loading…
Cancel
Save