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,10 +394,17 @@ 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):
try:
wallet_dirs = self.rpc("listwalletdir")
existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
except Exception:
existing = []
if len(existing) == 0:
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()}.'
) )
try: try:
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc( self.rpc(
"createwallet", "createwallet",
[ [
@@ -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,6 +4100,18 @@ 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:
try:
self.rpc("loadwallet", [self._rpc_wallet])
except Exception as e:
if "does not exist" in str(e) or "Path does not exist" in str(e):
try:
wallet_dirs = self.rpc("listwalletdir")
existing = [
w["name"] for w in wallet_dirs.get("wallets", [])
]
except Exception:
existing = []
if len(existing) == 0:
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()}.'
) )
@@ -4107,6 +4127,8 @@ class BTCInterface(Secp256k1Interface):
self._use_descriptors, self._use_descriptors,
], ],
) )
else:
raise
try: try:
seed_id = self.getWalletSeedID() seed_id = self.getWalletSeedID()

View File

@@ -50,10 +50,17 @@ 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):
try:
wallet_dirs = self.rpc("listwalletdir")
existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
except Exception:
existing = []
if len(existing) == 0:
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()}.'
) )
try: try:
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
self.rpc( self.rpc(
"createwallet", "createwallet",
[ [
@@ -192,9 +199,20 @@ 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:
try:
self.rpc("loadwallet", [self._rpc_wallet])
except Exception as e:
if "does not exist" in str(e) or "Path does not exist" in str(e):
try:
wallet_dirs = self.rpc("listwalletdir")
existing = [w["name"] for w in wallet_dirs.get("wallets", [])]
except Exception:
existing = []
if len(existing) == 0:
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",
[ [
@@ -206,6 +224,8 @@ class LTCInterface(BTCInterface):
self._use_descriptors, 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",
[ [