From 3f71dffe5a3e77d121ac0b5cf5d5d94aa3a5a8fe Mon Sep 17 00:00:00 2001 From: tecnovert Date: Mon, 12 Dec 2022 01:30:33 +0200 Subject: [PATCH] Fix Dash checkseed. --- basicswap/interface/dash.py | 7 +++++++ basicswap/protocols/__init__.py | 7 +++++++ basicswap/ui/page_offers.py | 18 ++++++++++++++++-- doc/install.md | 7 ++++++- tests/basicswap/extended/test_dash.py | 3 ++- tests/basicswap/extended/test_firo.py | 3 ++- tests/basicswap/extended/test_pivx.py | 6 +----- tests/basicswap/test_btc_xmr.py | 3 ++- tests/basicswap/test_run.py | 3 ++- tests/basicswap/test_xmr.py | 3 ++- 10 files changed, 47 insertions(+), 13 deletions(-) diff --git a/basicswap/interface/dash.py b/basicswap/interface/dash.py index f064523..31de3b1 100644 --- a/basicswap/interface/dash.py +++ b/basicswap/interface/dash.py @@ -23,6 +23,7 @@ class DASHInterface(BTCInterface): def __init__(self, coin_settings, network, swap_client=None): super().__init__(coin_settings, network, swap_client) self._wallet_passphrase = '' + self._have_checked_seed = False def seedToMnemonic(self, key): return Mnemonic('english').to_mnemonic(key) @@ -32,6 +33,9 @@ class DASHInterface(BTCInterface): mnemonic_passphrase = '' self.rpc_callback('upgradetohd', [words, mnemonic_passphrase, self._wallet_passphrase]) + self._have_checked_seed = False + if self._wallet_passphrase != '': + self.unlockWallet(self._wallet_passphrase) def decodeAddress(self, address): return decodeAddress(address)[1:] @@ -41,6 +45,7 @@ class DASHInterface(BTCInterface): rv = self.rpc_callback('dumphdinfo') entropy = Mnemonic('english').to_entropy(rv['mnemonic'].split(' ')) entropy_hash = self.getAddressHashFromKey(entropy)[::-1].hex() + self._have_checked_seed = True return entropy_hash == key_hash except Exception as e: self._log.warning('checkExpectedSeed failed: {}'.format(str(e))) @@ -81,6 +86,8 @@ class DASHInterface(BTCInterface): super().unlockWallet(password) # Store password for initialiseWallet self._wallet_passphrase = password + if not self._have_checked_seed: + self._sc.checkWalletSeed(self.coin_type()) def lockWallet(self): super().lockWallet() diff --git a/basicswap/protocols/__init__.py b/basicswap/protocols/__init__.py index 4867926..2ac2312 100644 --- a/basicswap/protocols/__init__.py +++ b/basicswap/protocols/__init__.py @@ -10,6 +10,9 @@ from basicswap.script import ( from basicswap.util.script import ( getP2WSH, ) +from basicswap.interface.btc import ( + find_vout_for_address_from_txobj, +) class ProtocolInterface: @@ -29,3 +32,7 @@ class ProtocolInterface: def getMockAddrTo(self, ci): script = self.getMockScript() return ci.encode_p2wsh(getP2WSH(script)) if ci._use_segwit else ci.encode_p2sh(script) + + def findMockVout(self, ci, itx_decoded): + mock_addr = self.getMockAddrTo(ci) + return find_vout_for_address_from_txobj(itx_decoded, mock_addr) diff --git a/basicswap/ui/page_offers.py b/basicswap/ui/page_offers.py index 4b42c60..e19fd55 100644 --- a/basicswap/ui/page_offers.py +++ b/basicswap/ui/page_offers.py @@ -177,6 +177,10 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}): page_data['automation_strat_id'] = int(get_data_entry_or(form_data, 'automation_strat_id', -1)) parsed_data['automation_strat_id'] = page_data['automation_strat_id'] + if have_data_entry(form_data, 'swap_type'): + parsed_data['swap_type'] = get_data_entry(form_data, 'swap_type') + if have_data_entry(form_data, 'subfee'): + parsed_data['subfee'] = True try: if len(errors) == 0 and page_data['swap_style'] == 'xmr': @@ -214,7 +218,7 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}): def postNewOfferFromParsed(swap_client, parsed_data): swap_type = SwapTypes.SELLER_FIRST - if swap_type in parsed_data: + if 'swap_type' in parsed_data: str_swap_type = parsed_data['swap_type'].lower() if str_swap_type == 'seller_first': swap_type = SwapTypes.SELLER_FIRST @@ -262,10 +266,20 @@ def postNewOfferFromParsed(swap_client, parsed_data): if parsed_data.get('automation_strat_id', None) is not None: extra_options['automation_id'] = parsed_data['automation_strat_id'] + swap_value = parsed_data['amt_from'] + if parsed_data.get('subfee', False): + ci_from = swap_client.ci(parsed_data['coin_from']) + pi = swap_client.pi(swap_type) + itx = pi.getFundedInitiateTxTemplate(ci_from, swap_value, True) + itx_decoded = ci_from.describeTx(itx.hex()) + n = pi.findMockVout(ci_from, itx_decoded) + swap_value = ci_from.make_int(itx_decoded['vout'][n]['value']) + extra_options = {'prefunded_itx': itx} + offer_id = swap_client.postOffer( parsed_data['coin_from'], parsed_data['coin_to'], - parsed_data['amt_from'], + swap_value, parsed_data['rate'], parsed_data['amt_bid_min'], swap_type, diff --git a/doc/install.md b/doc/install.md index 1858054..3066b15 100644 --- a/doc/install.md +++ b/doc/install.md @@ -90,12 +90,17 @@ Open in browser: `http://localhost:12700` docker-compose stop export COINDATA_PATH=/var/data/coinswaps - docker run --rm -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient basicswap-prepare --datadir=/coindata --addcoin=bitcoin + docker run --rm -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient basicswap-prepare --datadir=/coindata --addcoin=bitcoin --usebtcfastsync You can copy an existing pruned datadir (excluding bitcoin.conf and any wallets) over to `$COINDATA_PATH/bitcoin` Remove any existing wallets after copying over a pruned chain or the Bitcoin daemon won't start. +With Encryption + + export COINDATA_PATH=/var/data/coinswaps + docker run -e WALLET_ENCRYPTION_PWD=passwordhere --rm -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient basicswap-prepare --datadir=/coindata --addcoin=bitcoin --usebtcfastsync + ## Windows diff --git a/tests/basicswap/extended/test_dash.py b/tests/basicswap/extended/test_dash.py index c06e405..34ef9e6 100644 --- a/tests/basicswap/extended/test_dash.py +++ b/tests/basicswap/extended/test_dash.py @@ -622,7 +622,8 @@ class Test(unittest.TestCase): itx = pi.getFundedInitiateTxTemplate(ci_from, swap_value, True) itx_decoded = ci_from.describeTx(itx.hex()) - value_after_subfee = ci_from.make_int(itx_decoded['vout'][0]['value']) + n = pi.findMockVout(ci_from, itx_decoded) + value_after_subfee = ci_from.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee wait_for_unspent(delay_event, ci_from, swap_value) diff --git a/tests/basicswap/extended/test_firo.py b/tests/basicswap/extended/test_firo.py index 07723a8..51a32c1 100644 --- a/tests/basicswap/extended/test_firo.py +++ b/tests/basicswap/extended/test_firo.py @@ -472,7 +472,8 @@ class Test(BaseTest): itx = pi.getFundedInitiateTxTemplate(ci_from, swap_value, True) itx_decoded = ci_from.describeTx(itx.hex()) - value_after_subfee = ci_from.make_int(itx_decoded['vout'][0]['value']) + n = pi.findMockVout(ci_from, itx_decoded) + value_after_subfee = ci_from.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee wait_for_unspent(test_delay_event, ci_from, swap_value) diff --git a/tests/basicswap/extended/test_pivx.py b/tests/basicswap/extended/test_pivx.py index cb290a0..005bdfe 100644 --- a/tests/basicswap/extended/test_pivx.py +++ b/tests/basicswap/extended/test_pivx.py @@ -49,9 +49,6 @@ from basicswap.contrib.key import ( from basicswap.http_server import ( HttpThread, ) -from basicswap.interface.btc import ( - find_vout_for_address_from_txobj, -) from tests.basicswap.util import ( read_json_api, ) @@ -646,8 +643,7 @@ class Test(unittest.TestCase): itx = pi.getFundedInitiateTxTemplate(ci_from, swap_value, True) itx_decoded = ci_from.describeTx(itx.hex()) - mock_addr = pi.getMockAddrTo(ci_from) - n = find_vout_for_address_from_txobj(itx_decoded, mock_addr) + n = pi.findMockVout(ci_from, itx_decoded) value_after_subfee = ci_from.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee diff --git a/tests/basicswap/test_btc_xmr.py b/tests/basicswap/test_btc_xmr.py index 8deb64c..55ee1ad 100644 --- a/tests/basicswap/test_btc_xmr.py +++ b/tests/basicswap/test_btc_xmr.py @@ -554,7 +554,8 @@ class BasicSwapTest(BaseTest): itx = pi.getFundedInitiateTxTemplate(ci, swap_value, True) itx_decoded = ci.describeTx(itx.hex()) - value_after_subfee = ci.make_int(itx_decoded['vout'][0]['value']) + n = pi.findMockVout(ci, itx_decoded) + value_after_subfee = ci.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee wait_for_unspent(test_delay_event, ci, swap_value) diff --git a/tests/basicswap/test_run.py b/tests/basicswap/test_run.py index 85e71f1..d04e0b0 100644 --- a/tests/basicswap/test_run.py +++ b/tests/basicswap/test_run.py @@ -541,7 +541,8 @@ class Test(BaseTest): itx = pi.getFundedInitiateTxTemplate(ci, swap_value, True) itx_decoded = ci.describeTx(itx.hex()) - value_after_subfee = ci.make_int(itx_decoded['vout'][0]['value']) + n = pi.findMockVout(ci, itx_decoded) + value_after_subfee = ci.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee wait_for_unspent(test_delay_event, ci, swap_value) diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index b18206f..cf29c3a 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -1290,7 +1290,8 @@ class Test(BaseTest): itx = pi.getFundedInitiateTxTemplate(ci, swap_value, True) itx_decoded = ci.describeTx(itx.hex()) - value_after_subfee = ci.make_int(itx_decoded['vout'][0]['value']) + n = pi.findMockVout(ci, itx_decoded) + value_after_subfee = ci.make_int(itx_decoded['vout'][n]['value']) assert (value_after_subfee < swap_value) swap_value = value_after_subfee wait_for_unspent(test_delay_event, ci, swap_value)