From 8081f22e92c8838f2749766084653844a33632ac Mon Sep 17 00:00:00 2001 From: tecnovert Date: Mon, 14 Oct 2024 18:17:20 +0200 Subject: [PATCH] Fix intermittent DASH addcoin issue. --- basicswap/basicswap.py | 2 +- basicswap/interface/btc.py | 5 ++++- basicswap/interface/dash.py | 18 +++++++++++++----- basicswap/interface/dcr/dcr.py | 4 +++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 4fb907c..cf59f7d 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2042,7 +2042,7 @@ class BasicSwap(BaseApp): self.setStringKV(db_key, main_address, session) return main_address - def checkWalletSeed(self, c): + def checkWalletSeed(self, c) -> bool: ci = self.ci(c) if c == Coins.PART: ci.setWalletSeedWarning(False) # All keys should be be derived from the Particl mnemonic diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index 1a93f0d..05afb35 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -331,6 +331,7 @@ class BTCInterface(Secp256k1Interface): def initialiseWallet(self, key_bytes: bytes) -> None: key_wif = self.encodeKey(key_bytes) self.rpc_wallet('sethdseed', [True, key_wif]) + self._have_checked_seed = False def getWalletInfo(self): rv = self.rpc_wallet('getwalletinfo') @@ -368,8 +369,10 @@ class BTCInterface(Secp256k1Interface): return 'Not found' if 'hdseedid' not in wi else wi['hdseedid'] def checkExpectedSeed(self, expect_seedid: str) -> bool: + wallet_seed_id = self.getWalletSeedID() self._expect_seedid_hex = expect_seedid - return expect_seedid == self.getWalletSeedID() + self._have_checked_seed = True + return expect_seedid == wallet_seed_id def getNewAddress(self, use_segwit: bool, label: str = 'swap_receive') -> str: args = [label] diff --git a/basicswap/interface/dash.py b/basicswap/interface/dash.py index c8e4721..8549c16 100644 --- a/basicswap/interface/dash.py +++ b/basicswap/interface/dash.py @@ -38,6 +38,7 @@ class DASHInterface(BTCInterface): return Mnemonic('english').to_mnemonic(key) def initialiseWallet(self, key_bytes: bytes) -> None: + self._have_checked_seed = False if self._wallet_v20_compatible: self._log.warning('Generating wallet compatible with v20 seed.') words = self.entropyToMnemonic(key_bytes) @@ -57,9 +58,11 @@ class DASHInterface(BTCInterface): if rv['mnemonic'] != '': entropy = Mnemonic('english').to_entropy(rv['mnemonic'].split(' ')) entropy_hash = self.getAddressHashFromKey(entropy)[::-1].hex() - return expect_seedid == entropy_hash + have_expected_seed: bool = expect_seedid == entropy_hash else: - return expect_seedid == self.getWalletSeedID() + have_expected_seed: bool = expect_seedid == self.getWalletSeedID() + self._have_checked_seed = True + return have_expected_seed def withdrawCoin(self, value, addr_to, subfee): params = [addr_to, value, '', '', subfee, False, False, self._conf_target] @@ -94,10 +97,15 @@ class DASHInterface(BTCInterface): def unlockWallet(self, password: str): super().unlockWallet(password) - # Store password for initialiseWallet - self._wallet_passphrase = password + if self._wallet_v20_compatible: + # Store password for initialiseWallet + self._wallet_passphrase = password if not self._have_checked_seed: - self._sc.checkWalletSeed(self.coin_type()) + try: + self._sc.checkWalletSeed(self.coin_type()) + except Exception as ex: + # dumphdinfo can fail if the wallet is not initialised + self._log.debug(f'DASH checkWalletSeed failed: {ex}.') def lockWallet(self): super().lockWallet() diff --git a/basicswap/interface/dcr/dcr.py b/basicswap/interface/dcr/dcr.py index a740ffd..4c0afa7 100644 --- a/basicswap/interface/dcr/dcr.py +++ b/basicswap/interface/dcr/dcr.py @@ -372,7 +372,9 @@ class DCRInterface(Secp256k1Interface): def checkExpectedSeed(self, expect_seedid) -> bool: self._expect_seedid_hex = expect_seedid - return expect_seedid == self.getWalletSeedID() + rv: bool = expect_seedid == self.getWalletSeedID() + self._have_checked_seed = True + return rv def getDaemonVersion(self): return self.rpc('getnetworkinfo')['version']