mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-23 03:49:25 +00:00
Fix getLinkedMessageId and validateSwapType
This commit is contained in:
parent
a13a5d4bf6
commit
8f4b962285
5 changed files with 56 additions and 16 deletions
|
@ -1,3 +1,3 @@
|
||||||
name = "basicswap"
|
name = "basicswap"
|
||||||
|
|
||||||
__version__ = "0.11.65"
|
__version__ = "0.11.66"
|
||||||
|
|
|
@ -266,7 +266,7 @@ class BasicSwap(BaseApp):
|
||||||
# TODO: Set dynamically
|
# TODO: Set dynamically
|
||||||
self.scriptless_coins = (Coins.XMR, Coins.PART_ANON)
|
self.scriptless_coins = (Coins.XMR, Coins.PART_ANON)
|
||||||
self.adaptor_swap_only_coins = self.scriptless_coins + (Coins.PART_BLIND, )
|
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
|
# TODO: Adjust ranges
|
||||||
self.min_delay_event = self.settings.get('min_delay_event', 10)
|
self.min_delay_event = self.settings.get('min_delay_event', 10)
|
||||||
|
@ -1145,14 +1145,16 @@ class BasicSwap(BaseApp):
|
||||||
return bytes.fromhex(ro['msgid'])
|
return bytes.fromhex(ro['msgid'])
|
||||||
|
|
||||||
def validateSwapType(self, coin_from, coin_to, swap_type):
|
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 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))
|
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):
|
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))
|
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:
|
def notify(self, event_type, event_data, session=None) -> None:
|
||||||
show_event = event_type not in self._disabled_notification_types
|
show_event = event_type not in self._disabled_notification_types
|
||||||
|
@ -2066,7 +2068,7 @@ class BasicSwap(BaseApp):
|
||||||
def getLinkedMessageId(self, linked_type: int, linked_id: int, msg_type: int, msg_sequence: int = 0, session=None) -> bytes:
|
def getLinkedMessageId(self, linked_type: int, linked_id: int, msg_type: int, msg_sequence: int = 0, session=None) -> bytes:
|
||||||
try:
|
try:
|
||||||
use_session = self.openSession(session)
|
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',
|
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()
|
{'linked_type': linked_type, 'linked_id': linked_id, 'msg_type': msg_type, 'msg_sequence': msg_sequence}).first()
|
||||||
return q[0]
|
return q[0]
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
|
|
||||||
|
0.0.66
|
||||||
|
==============
|
||||||
|
- Fixed bugs in getLinkedMessageId and validateSwapType.
|
||||||
|
|
||||||
|
|
||||||
|
0.0.65
|
||||||
|
==============
|
||||||
|
|
||||||
|
- 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
|
0.0.64
|
||||||
==============
|
==============
|
||||||
|
|
||||||
- protocol: Added reversed Adaptor sig protocol.
|
- protocol: Added reversed Adaptor sig protocol.
|
||||||
- Runs the adaptor-sig protocol with leader and follower swapped to
|
- Runs the adaptor-sig protocol with leader and follower swapped to
|
||||||
enable offers from no-script coins to script coins.
|
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
|
|
||||||
- Raised adaptor signature swap protocol version
|
- Raised adaptor signature swap protocol version
|
||||||
- Not backwards compatible with previous versions.
|
- Not backwards compatible with previous versions.
|
||||||
- ui: Show ITX and PTX status for adaptor sig type swaps.
|
|
||||||
|
|
||||||
|
|
||||||
0.0.63
|
0.0.63
|
||||||
|
|
|
@ -506,9 +506,10 @@ class BasicSwapTest(TestFunctions):
|
||||||
tx_spend_hex = ToHex(tx_spend)
|
tx_spend_hex = ToHex(tx_spend)
|
||||||
try:
|
try:
|
||||||
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
||||||
assert False, 'Should fail'
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert ('non-final' in str(e))
|
assert ('non-final' in str(e))
|
||||||
|
else:
|
||||||
|
assert False, 'Should fail'
|
||||||
|
|
||||||
self.mineBlock(5)
|
self.mineBlock(5)
|
||||||
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
||||||
|
@ -551,9 +552,10 @@ class BasicSwapTest(TestFunctions):
|
||||||
tx_spend_hex = ToHex(tx_spend)
|
tx_spend_hex = ToHex(tx_spend)
|
||||||
try:
|
try:
|
||||||
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
||||||
assert False, 'Should fail'
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert ('non-BIP68-final' in str(e))
|
assert ('non-BIP68-final' in str(e))
|
||||||
|
else:
|
||||||
|
assert False, 'Should fail'
|
||||||
|
|
||||||
self.mineBlock(3)
|
self.mineBlock(3)
|
||||||
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
txid = self.callnoderpc('sendrawtransaction', [tx_spend_hex, ])
|
||||||
|
|
|
@ -166,6 +166,31 @@ class Test(BaseTest):
|
||||||
rv = read_json_api(1800, 'automationstrategies/1')
|
rv = read_json_api(1800, 'automationstrategies/1')
|
||||||
assert (rv['label'] == 'Accept All')
|
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):
|
def test_01_verifyrawtransaction(self):
|
||||||
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
|
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
|
||||||
prevout = {
|
prevout = {
|
||||||
|
|
Loading…
Reference in a new issue