diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 5333926..5613682 100644 --- a/basicswap/basicswap.py +++ b/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())) diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index e3cf450..d60b15d 100644 --- a/basicswap/interface/btc.py +++ b/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: diff --git a/basicswap/interface/dash.py b/basicswap/interface/dash.py index 67b8584..4597ecc 100644 --- a/basicswap/interface/dash.py +++ b/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] diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 098674f..057304c 100755 --- a/bin/basicswap_prepare.py +++ b/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) diff --git a/requirements.txt b/requirements.txt index 1c79fb8..bbc8f65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ Jinja2 requests pycryptodome PySocks +mnemonic diff --git a/setup.py b/setup.py index 1005d17..d21a0f7 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ setuptools.setup( "requests", "pycryptodome", "PySocks", + "mnemonic", ], entry_points={ "console_scripts": [ diff --git a/tests/basicswap/extended/test_dash.py b/tests/basicswap/extended/test_dash.py index eaf7bd4..5a659d4 100644 --- a/tests/basicswap/extended/test_dash.py +++ b/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')