Fix Dash checkseed.

This commit is contained in:
tecnovert 2022-12-12 01:30:33 +02:00
parent 2a9e423eaa
commit 3f71dffe5a
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
10 changed files with 47 additions and 13 deletions

View file

@ -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()

View file

@ -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)

View file

@ -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,

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)