From d037fbb9024f72adf32f1a1997b13aca9764bf22 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 20 Oct 2025 10:49:02 -0700 Subject: [PATCH] Fix RPC key deletion endpoints to actually delete intended DBs --- chia/_tests/wallet/rpc/test_wallet_rpc.py | 10 +++++++++- chia/wallet/wallet_rpc_api.py | 20 +++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/chia/_tests/wallet/rpc/test_wallet_rpc.py b/chia/_tests/wallet/rpc/test_wallet_rpc.py index 805191ced1c1..e61435907896 100644 --- a/chia/_tests/wallet/rpc/test_wallet_rpc.py +++ b/chia/_tests/wallet/rpc/test_wallet_rpc.py @@ -101,7 +101,7 @@ from chia.wallet.wallet import Wallet from chia.wallet.wallet_coin_record import WalletCoinRecord from chia.wallet.wallet_coin_store import GetCoinRecords -from chia.wallet.wallet_node import WalletNode +from chia.wallet.wallet_node import WalletNode, get_wallet_db_path from chia.wallet.wallet_protocol import WalletProtocol from chia.wallet.wallet_request_types import ( AddKey, @@ -2340,7 +2340,9 @@ async def test_key_and_address_endpoints(wallet_rpc_environment: WalletRpcTestEn assert delete_key_resp.used_for_farmer_rewards is False assert delete_key_resp.used_for_pool_rewards is False + assert get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(pks[0])).exists() await client.delete_key(DeleteKey(pks[0])) + assert not get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(pks[0])).exists() await client.log_in(LogIn(uint32(pks[1]))) assert len((await client.get_public_keys()).pk_fingerprints) == 1 @@ -2357,7 +2359,13 @@ async def test_key_and_address_endpoints(wallet_rpc_environment: WalletRpcTestEn ) # Delete all keys + resp = await client.generate_mnemonic() + add_key_resp = await client.add_key(AddKey(resp.mnemonic)) + assert get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(pks[1])).exists() + assert get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(add_key_resp.fingerprint)).exists() await client.delete_all_keys() + assert not get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(pks[1])).exists() + assert not get_wallet_db_path(wallet_node.root_path, wallet_node.config, str(add_key_resp.fingerprint)).exists() assert len((await client.get_public_keys()).pk_fingerprints) == 0 diff --git a/chia/wallet/wallet_rpc_api.py b/chia/wallet/wallet_rpc_api.py index 3c951f6c6292..329061ac7c7e 100644 --- a/chia/wallet/wallet_rpc_api.py +++ b/chia/wallet/wallet_rpc_api.py @@ -31,7 +31,6 @@ from chia.util.errors import KeychainIsLocked from chia.util.hash import std_hash from chia.util.keychain import bytes_to_mnemonic, generate_mnemonic -from chia.util.path import path_from_root from chia.util.streamable import Streamable, UInt32Range, streamable from chia.util.ws_message import WsRpcMessage, create_payload_dict from chia.wallet.cat_wallet.cat_constants import DEFAULT_CATS @@ -104,7 +103,7 @@ from chia.wallet.wallet_coin_record import WalletCoinRecord from chia.wallet.wallet_coin_store import CoinRecordOrder, GetCoinRecords, unspent_range from chia.wallet.wallet_info import WalletInfo -from chia.wallet.wallet_node import WalletNode +from chia.wallet.wallet_node import WalletNode, get_wallet_db_path from chia.wallet.wallet_protocol import WalletProtocol from chia.wallet.wallet_request_types import ( AddKey, @@ -838,9 +837,10 @@ async def delete_key(self, request: DeleteKey) -> Empty: except Exception as e: log.error(f"Failed to delete key by fingerprint: {e}") raise e - path = path_from_root( + path = get_wallet_db_path( self.service.root_path, - f"{self.service.config['database_path']}-{request.fingerprint}", + self.service.config, + str(request.fingerprint), ) if path.exists(): path.unlink() @@ -928,14 +928,20 @@ async def check_delete_key(self, request: CheckDeleteKey) -> CheckDeleteKeyRespo @marshal async def delete_all_keys(self, request: Empty) -> Empty: await self._stop_wallet() + all_key_datas = await self.service.keychain_proxy.get_keys() try: await self.service.keychain_proxy.delete_all_keys() except Exception as e: log.error(f"Failed to delete all keys: {e}") raise e - path = path_from_root(self.service.root_path, self.service.config["database_path"]) - if path.exists(): - path.unlink() + for key_data in all_key_datas: + path = get_wallet_db_path( + self.service.root_path, + self.service.config, + str(key_data.fingerprint), + ) + if path.exists(): + path.unlink() return Empty() ##########################################################################################