Browse Source

dash: Fix initialiseWallet

Only the upgradetohd command sets the hdseed
upgradetohd can only run once the chain is synced

Basicswap stores the hash of the root_key in it's db to check for the expected seed.
Prefer not to store the real key.
dash_v2
tecnovert 2 years ago
parent
commit
aa14da27af
No known key found for this signature in database GPG Key ID: 8ED6D8750C4E3F93
  1. 4
      basicswap/basicswap.py
  2. 3
      basicswap/interface/btc.py
  3. 14
      basicswap/interface/dash.py
  4. 5
      bin/basicswap_prepare.py
  5. 1
      requirements.txt
  6. 1
      setup.py
  7. 9
      tests/basicswap/extended/test_dash.py

4
basicswap/basicswap.py

@ -980,6 +980,8 @@ class BasicSwap(BaseApp):
raise ValueError('Invalid swap type for PART_BLIND')
if coin_from == Coins.PIVX and swap_type == SwapTypes.XMR_SWAP:
raise ValueError('TODO: PIVX -> XMR')
if coin_from == Coins.DASH and swap_type == SwapTypes.XMR_SWAP:
raise ValueError('TODO: DASH -> XMR')
def notify(self, event_type, event_data, session=None):
@ -1497,7 +1499,7 @@ class BasicSwap(BaseApp):
if expect_seedid is None:
self.log.warning('Can\'t find expected wallet seed id for coin {}'.format(ci.coin_name()))
return False
if expect_seedid == ci.getWalletSeedID():
if ci.checkExpectedSeed(expect_seedid):
ci.setWalletSeedWarning(False)
return True
self.log.warning('Wallet for coin {} not derived from swap seed.'.format(ci.coin_name()))

3
basicswap/interface/btc.py

@ -293,6 +293,9 @@ class BTCInterface(CoinInterface):
def getWalletSeedID(self):
return self.rpc_callback('getwalletinfo')['hdseedid']
def checkExpectedSeed(self, expect_seedid):
return expect_seedid == self.getWalletSeedID()
def getNewAddress(self, use_segwit, label='swap_receive'):
args = [label]
if use_segwit:

14
basicswap/interface/dash.py

@ -7,6 +7,7 @@
from .btc import BTCInterface
from basicswap.chainparams import Coins
from mnemonic import Mnemonic
class DASHInterface(BTCInterface):
@ -15,7 +16,18 @@ class DASHInterface(BTCInterface):
return Coins.DASH
def initialiseWallet(self, key):
raise ValueError('Load seed with with -hdseed daemon argument')
words = Mnemonic('english').to_mnemonic(key)
self.rpc_callback('upgradetohd', [words, ])
def checkExpectedSeed(self, key_hash):
try:
rv = self.rpc_callback('dumphdinfo')
entropy = Mnemonic('english').to_entropy(rv['mnemonic'].split(' '))
entropy_hash = self.getAddressHashFromKey(entropy)[::-1].hex()
return entropy_hash == key_hash
except Exception as e:
self._log.warning('checkExpectedSeed failed: {}'.format(str(e)))
return False
def withdrawCoin(self, value, addr_to, subfee):
params = [addr_to, value, '', '', subfee]

5
bin/basicswap_prepare.py

@ -885,9 +885,6 @@ def initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings,
filename = coin_name + 'd' + ('.exe' if os.name == 'nt' else '')
coin_args = ['-nofindpeers', '-nostaking'] if c == Coins.PART else []
if c == Coins.DASH:
coin_args += ['-hdseed={}'.format(swap_client.getWalletKey(Coins.DASH, 1).hex())]
daemons.append(startDaemon(coin_settings['datadir'], coin_settings['bindir'], filename, daemon_args + coin_args))
swap_client.setDaemonPID(c, daemons[-1].pid)
swap_client.setCoinRunParams(c)
@ -909,7 +906,7 @@ def initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings,
for coin_name in with_coins:
c = swap_client.getCoinIdFromName(coin_name)
if c in (Coins.PART, Coins.DASH):
if c in (Coins.PART, ):
continue
swap_client.waitForDaemonRPC(c)
swap_client.initialiseWallet(c)

1
requirements.txt

@ -7,3 +7,4 @@ Jinja2
requests
pycryptodome
PySocks
mnemonic

1
setup.py

@ -40,6 +40,7 @@ setuptools.setup(
"requests",
"pycryptodome",
"PySocks",
"mnemonic",
],
entry_points={
"console_scripts": [

9
tests/basicswap/extended/test_dash.py

@ -540,6 +540,15 @@ class Test(unittest.TestCase):
json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/dash/withdraw'.format(TEST_HTTP_PORT + 0), post_json))
assert (len(json_rv['txid']) == 64)
def test_09_initialise_wallet(self):
logging.info('---------- Test DASH initialiseWallet')
self.swap_clients[0].initialiseWallet(Coins.DASH, raise_errors=True)
assert self.swap_clients[0].checkWalletSeed(Coins.DASH) is True
pivx_addr = dashRpc('getnewaddress \"hd test\"')
assert pivx_addr == 'ybzWYJbZEhZai8kiKkTtPFKTuDNwhpiwac'
def pass_99_delay(self):
global stop_test
logging.info('Delay')

Loading…
Cancel
Save