Fix: Prevent silent wallet creation. (#444)

* Fix: Prevent silent wallet creation.

* Error on wallet name mismatch + fix wording.

* Revert init_wallet

* Don't create wallet on startup if other wallets exist on disk.

* Added back # wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
This commit is contained in:
Gerlof van Ek
2026-04-07 22:27:03 +02:00
committed by GitHub
parent c58e637987
commit 3c76454e68
2 changed files with 112 additions and 69 deletions

View File

@@ -394,29 +394,36 @@ class BTCInterface(Secp256k1Interface):
except Exception as e: except Exception as e:
self._log.debug(f'Error loading wallet "{self._rpc_wallet}": {e}.') self._log.debug(f'Error loading wallet "{self._rpc_wallet}": {e}.')
if "does not exist" in str(e) or "Path does not exist" in str(e): if "does not exist" in str(e) or "Path does not exist" in str(e):
self._log.info(
f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
)
try: try:
self.rpc( wallet_dirs = self.rpc("listwalletdir")
"createwallet", existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
[ except Exception:
self._rpc_wallet, existing = []
False, if len(existing) == 0:
True, self._log.info(
"", f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
False,
self._use_descriptors,
],
) )
wallets = self.rpc("listwallets") try:
if self.getWalletSeedID() == "Not found": # wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self._log.info( self.rpc(
f"Initializing HD seed for {self.coin_name()}." "createwallet",
[
self._rpc_wallet,
False,
True,
"",
False,
self._use_descriptors,
],
) )
self._sc.initialiseWallet(self.coin_type()) wallets = self.rpc("listwallets")
except Exception as create_e: if self.getWalletSeedID() == "Not found":
self._log.error(f"Error creating wallet: {create_e}") self._log.info(
f"Initializing HD seed for {self.coin_name()}."
)
self._sc.initialiseWallet(self.coin_type())
except Exception as create_e:
self._log.error(f"Error creating wallet: {create_e}")
# Wallet name is "" for some LTC and PART installs on older cores # Wallet name is "" for some LTC and PART installs on older cores
if self._rpc_wallet not in wallets and len(wallets) > 0: if self._rpc_wallet not in wallets and len(wallets) > 0:
@@ -3842,6 +3849,7 @@ class BTCInterface(Secp256k1Interface):
def createWallet(self, wallet_name: str, password: str = "") -> None: def createWallet(self, wallet_name: str, password: str = "") -> None:
if self._connection_type == "electrum": if self._connection_type == "electrum":
return return
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc( self.rpc(
"createwallet", "createwallet",
[wallet_name, False, True, password, False, self._use_descriptors], [wallet_name, False, True, password, False, self._use_descriptors],
@@ -4092,21 +4100,35 @@ class BTCInterface(Secp256k1Interface):
# Required when encrypting an existing btc/ltc wallet, or switching from electrum to rpc mode. Workaround is to delete the btc/ltc wallet and recreate. # Required when encrypting an existing btc/ltc wallet, or switching from electrum to rpc mode. Workaround is to delete the btc/ltc wallet and recreate.
wallets = self.rpc("listwallets") wallets = self.rpc("listwallets")
if self._rpc_wallet not in wallets: if self._rpc_wallet not in wallets:
self._log.info( try:
f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.' self.rpc("loadwallet", [self._rpc_wallet])
) except Exception as e:
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors if "does not exist" in str(e) or "Path does not exist" in str(e):
self.rpc( try:
"createwallet", wallet_dirs = self.rpc("listwalletdir")
[ existing = [
self._rpc_wallet, w["name"] for w in wallet_dirs.get("wallets", [])
False, ]
True, except Exception:
password, existing = []
False, if len(existing) == 0:
self._use_descriptors, self._log.info(
], f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
) )
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc(
"createwallet",
[
self._rpc_wallet,
False,
True,
password,
False,
self._use_descriptors,
],
)
else:
raise
try: try:
seed_id = self.getWalletSeedID() seed_id = self.getWalletSeedID()

View File

@@ -50,29 +50,36 @@ class LTCInterface(BTCInterface):
except Exception as e: except Exception as e:
self._log.debug(f'Error loading wallet "{self._rpc_wallet}": {e}.') self._log.debug(f'Error loading wallet "{self._rpc_wallet}": {e}.')
if "does not exist" in str(e) or "Path does not exist" in str(e): if "does not exist" in str(e) or "Path does not exist" in str(e):
self._log.info(
f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
)
try: try:
self.rpc( wallet_dirs = self.rpc("listwalletdir")
"createwallet", existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
[ except Exception:
self._rpc_wallet, existing = []
False, if len(existing) == 0:
True, self._log.info(
"", f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
False,
self._use_descriptors,
],
) )
wallets = self.rpc("listwallets") try:
if self.getWalletSeedID() == "Not found": # wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self._log.info( self.rpc(
f"Initializing HD seed for {self.coin_name()}." "createwallet",
[
self._rpc_wallet,
False,
True,
"",
False,
self._use_descriptors,
],
) )
self._sc.initialiseWallet(self.coin_type()) wallets = self.rpc("listwallets")
except Exception as create_e: if self.getWalletSeedID() == "Not found":
self._log.error(f"Error creating wallet: {create_e}") self._log.info(
f"Initializing HD seed for {self.coin_name()}."
)
self._sc.initialiseWallet(self.coin_type())
except Exception as create_e:
self._log.error(f"Error creating wallet: {create_e}")
if self._rpc_wallet not in wallets and len(wallets) > 0: if self._rpc_wallet not in wallets and len(wallets) > 0:
self._log.warning(f"Changing {self.ticker()} wallet name.") self._log.warning(f"Changing {self.ticker()} wallet name.")
@@ -192,20 +199,33 @@ class LTCInterface(BTCInterface):
wallets = self.rpc("listwallets") wallets = self.rpc("listwallets")
if self._rpc_wallet not in wallets: if self._rpc_wallet not in wallets:
self._log.info( try:
f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.' self.rpc("loadwallet", [self._rpc_wallet])
) except Exception as e:
self.rpc( if "does not exist" in str(e) or "Path does not exist" in str(e):
"createwallet", try:
[ wallet_dirs = self.rpc("listwalletdir")
self._rpc_wallet, existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
False, except Exception:
True, existing = []
password, if len(existing) == 0:
False, self._log.info(
self._use_descriptors, f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
], )
) # wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc(
"createwallet",
[
self._rpc_wallet,
False,
True,
password,
False,
self._use_descriptors,
],
)
else:
raise
try: try:
seed_id = self.getWalletSeedID() seed_id = self.getWalletSeedID()
@@ -298,6 +318,7 @@ class LTCInterfaceMWEB(LTCInterface):
self._log.info( self._log.info(
f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.' f'Creating wallet "{self._rpc_wallet}" for {self.coin_name()}.'
) )
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc( self.rpc(
"createwallet", "createwallet",
[ [