Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion chia/_tests/wallet/rpc/test_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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


Expand Down
20 changes: 13 additions & 7 deletions chia/wallet/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

##########################################################################################
Expand Down
Loading