From 1fcee62b218867573deb0415a6a36de582eb1c09 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 15 Oct 2024 17:04:04 +0200 Subject: [PATCH] Better handle incorrect password. --- bittensor_cli/src/bittensor/async_substrate_interface.py | 2 +- bittensor_cli/src/bittensor/extrinsics/registration.py | 1 + bittensor_cli/src/bittensor/extrinsics/root.py | 2 ++ bittensor_cli/src/bittensor/extrinsics/transfer.py | 1 + bittensor_cli/src/commands/root.py | 5 +++++ bittensor_cli/src/commands/stake/stake.py | 4 ++++ bittensor_cli/src/commands/subnets.py | 1 + bittensor_cli/src/commands/sudo.py | 1 + bittensor_cli/src/commands/wallets.py | 1 + 9 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/src/bittensor/async_substrate_interface.py b/bittensor_cli/src/bittensor/async_substrate_interface.py index 0f4dd0d4..0c40830d 100644 --- a/bittensor_cli/src/bittensor/async_substrate_interface.py +++ b/bittensor_cli/src/bittensor/async_substrate_interface.py @@ -682,9 +682,9 @@ async def shutdown(self): try: self._receiving_task.cancel() await self._receiving_task + await self.ws.close() except (AttributeError, asyncio.CancelledError): pass - await self.ws.close() self.ws = None self._initialized = False self._receiving_task = None diff --git a/bittensor_cli/src/bittensor/extrinsics/registration.py b/bittensor_cli/src/bittensor/extrinsics/registration.py index 5354ac52..6373824f 100644 --- a/bittensor_cli/src/bittensor/extrinsics/registration.py +++ b/bittensor_cli/src/bittensor/extrinsics/registration.py @@ -1630,6 +1630,7 @@ async def swap_hotkey_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False if prompt: diff --git a/bittensor_cli/src/bittensor/extrinsics/root.py b/bittensor_cli/src/bittensor/extrinsics/root.py index fcbf7d0c..295ee640 100644 --- a/bittensor_cli/src/bittensor/extrinsics/root.py +++ b/bittensor_cli/src/bittensor/extrinsics/root.py @@ -309,6 +309,7 @@ async def root_register_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False print_verbose(f"Checking if hotkey ({wallet.hotkey_str}) is registered on root") @@ -429,6 +430,7 @@ async def _do_set_weights(): try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False # First convert types. diff --git a/bittensor_cli/src/bittensor/extrinsics/transfer.py b/bittensor_cli/src/bittensor/extrinsics/transfer.py index 8ae37e9b..620c20d7 100644 --- a/bittensor_cli/src/bittensor/extrinsics/transfer.py +++ b/bittensor_cli/src/bittensor/extrinsics/transfer.py @@ -111,6 +111,7 @@ async def do_transfer() -> tuple[bool, str, str]: try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False # Check balance. diff --git a/bittensor_cli/src/commands/root.py b/bittensor_cli/src/commands/root.py index 9a19c736..2401eb00 100644 --- a/bittensor_cli/src/commands/root.py +++ b/bittensor_cli/src/commands/root.py @@ -283,6 +283,7 @@ async def burned_register_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False with console.status( @@ -539,6 +540,7 @@ async def get_stake_for_coldkey_and_hotkey( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False print_verbose("Checking if hotkey is a delegate") @@ -1100,6 +1102,7 @@ async def senate_vote( wallet.unlock_hotkey() wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False console.print(f"Fetching proposals in [dark_orange]network: {subtensor.network}") @@ -1323,6 +1326,7 @@ async def _do_set_take() -> bool: wallet.unlock_hotkey() wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False result_ = await _do_set_take() @@ -1724,6 +1728,7 @@ async def nominate(wallet: Wallet, subtensor: SubtensorInterface, prompt: bool): wallet.unlock_hotkey() wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False print_verbose(f"Checking hotkey ({wallet.hotkey_str}) is a delegate") diff --git a/bittensor_cli/src/commands/stake/stake.py b/bittensor_cli/src/commands/stake/stake.py index 0f48d619..819f02cc 100644 --- a/bittensor_cli/src/commands/stake/stake.py +++ b/bittensor_cli/src/commands/stake/stake.py @@ -106,6 +106,7 @@ async def add_stake_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False # Default to wallet's own hotkey if the value is not passed. @@ -312,6 +313,7 @@ async def add_stake_multiple_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False with console.status( @@ -493,6 +495,7 @@ async def unstake_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False if hotkey_ss58 is None: @@ -663,6 +666,7 @@ async def unstake_multiple_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False with console.status( diff --git a/bittensor_cli/src/commands/subnets.py b/bittensor_cli/src/commands/subnets.py index 122fec6a..3e934982 100644 --- a/bittensor_cli/src/commands/subnets.py +++ b/bittensor_cli/src/commands/subnets.py @@ -103,6 +103,7 @@ async def _find_event_attributes_in_extrinsic_receipt( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False with console.status(":satellite: Registering subnet...", spinner="earth"): diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index 26cdab5f..6ebbb0ec 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -104,6 +104,7 @@ async def set_hyperparameter_extrinsic( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False extrinsic = HYPERPARAMS.get(parameter) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index a1dd2262..3faefd23 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -1619,6 +1619,7 @@ async def set_id( try: wallet.unlock_coldkey() except KeyFileError: + err_console.print("Error decrypting coldkey (possibly incorrect password)") return False with console.status(