Skip to content

Commit 3e93c8d

Browse files
committed
Cleanup/ruff
1 parent 8603a54 commit 3e93c8d

File tree

5 files changed

+35
-45
lines changed

5 files changed

+35
-45
lines changed

bittensor_cli/cli.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -963,13 +963,13 @@ async def _run():
963963
finally:
964964
if initiated is False:
965965
asyncio.create_task(cmd).cancel()
966-
if exit_early is True: # temporarily to handle multiple run commands in one session
966+
if (
967+
exit_early is True
968+
): # temporarily to handle multiple run commands in one session
967969
try:
968970
raise typer.Exit()
969971
except Exception as e: # ensures we always exit cleanly
970-
if not isinstance(
971-
e, (typer.Exit, RuntimeError)
972-
):
972+
if not isinstance(e, (typer.Exit, RuntimeError)):
973973
err_console.print(f"An unknown error has occurred: {e}")
974974

975975
return self.asyncio_runner(_run())
@@ -2209,7 +2209,9 @@ def wallet_new_hotkey(
22092209
)
22102210
if not uri:
22112211
n_words = get_n_words(n_words)
2212-
return self._run_command(wallets.new_hotkey(wallet, n_words, use_password, uri, overwrite))
2212+
return self._run_command(
2213+
wallets.new_hotkey(wallet, n_words, use_password, uri, overwrite)
2214+
)
22132215

22142216
def wallet_new_coldkey(
22152217
self,
@@ -2344,13 +2346,7 @@ def wallet_create_wallet(
23442346
if not uri:
23452347
n_words = get_n_words(n_words)
23462348
return self._run_command(
2347-
wallets.wallet_create(
2348-
wallet,
2349-
n_words,
2350-
use_password,
2351-
uri,
2352-
overwrite
2353-
)
2349+
wallets.wallet_create(wallet, n_words, use_password, uri, overwrite)
23542350
)
23552351

23562352
def wallet_balance(

bittensor_cli/src/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55

66
class Constants:
7-
networks = ["local", "finney", "test", "archive", "subvortex", "rao", "dev", "latent-lite"]
7+
networks = [
8+
"local",
9+
"finney",
10+
"test",
11+
"archive",
12+
"subvortex",
13+
"rao",
14+
"dev",
15+
"latent-lite",
16+
]
817
finney_entrypoint = "wss://entrypoint-finney.opentensor.ai:443"
918
finney_test_entrypoint = "wss://test.finney.opentensor.ai:443"
1019
archive_entrypoint = "wss://archive.chain.opentensor.ai:443"
@@ -664,7 +673,10 @@ class WalletValidationTypes(Enum):
664673
"alpha_values": ("sudo_set_alpha_values", False),
665674
"liquid_alpha_enabled": ("sudo_set_liquid_alpha_enabled", False),
666675
"network_registration_allowed": ("sudo_set_network_registration_allowed", False),
667-
"network_pow_registration_allowed": ("sudo_set_network_pow_registration_allowed", False)
676+
"network_pow_registration_allowed": (
677+
"sudo_set_network_pow_registration_allowed",
678+
False,
679+
),
668680
}
669681

670682
# Help Panels for cli help

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
err_console,
3131
decode_hex_identity_dict,
3232
validate_chain_endpoint,
33-
u16_normalized_float
33+
u16_normalized_float,
3434
)
3535

3636

bittensor_cli/src/bittensor/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,11 +1293,14 @@ def is_linux():
12931293
"""Returns True if the operating system is Linux."""
12941294
return platform.system().lower() == "linux"
12951295

1296+
12961297
def validate_rate_tolerance(value: Optional[float]) -> Optional[float]:
12971298
"""Validates rate tolerance input"""
12981299
if value is not None:
12991300
if value < 0:
1300-
raise typer.BadParameter("Rate tolerance cannot be negative (less than 0%).")
1301+
raise typer.BadParameter(
1302+
"Rate tolerance cannot be negative (less than 0%)."
1303+
)
13011304
if value > 1:
13021305
raise typer.BadParameter("Rate tolerance cannot be greater than 1 (100%).")
13031306
if value > 0.5:

bittensor_cli/src/commands/wallets.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
get_subnet_name,
4545
millify_tao,
4646
unlock_key,
47-
hex_to_bytes,
4847
WalletLike,
4948
)
5049

@@ -1076,12 +1075,11 @@ async def transfer(
10761075
):
10771076
"""Transfer token of amount to destination."""
10781077
await transfer_extrinsic(
1079-
# TODO verify the order here
1080-
subtensor,
1081-
wallet,
1082-
destination,
1083-
Balance.from_tao(amount),
1084-
transfer_all,
1078+
subtensor=subtensor,
1079+
wallet=wallet,
1080+
destination=destination,
1081+
amount=Balance.from_tao(amount),
1082+
transfer_all=transfer_all,
10851083
prompt=prompt,
10861084
)
10871085

@@ -1335,11 +1333,7 @@ async def set_id(
13351333
)
13361334
return False
13371335

1338-
try:
1339-
# TODO unlock fn
1340-
wallet.unlock_coldkey()
1341-
except KeyFileError:
1342-
err_console.print("Error decrypting coldkey (possibly incorrect password)")
1336+
if not unlock_key(wallet).success:
13431337
return False
13441338

13451339
call = await subtensor.substrate.compose_call(
@@ -1431,30 +1425,15 @@ async def check_coldkey_swap(wallet: Wallet, subtensor: SubtensorInterface):
14311425
async def sign(wallet: Wallet, message: str, use_hotkey: str):
14321426
"""Sign a message using the provided wallet or hotkey."""
14331427

1434-
def _unlock(key: str):
1435-
try:
1436-
getattr(wallet, f"unlock_{key}")()
1437-
return True
1438-
except PasswordError:
1439-
err_console.print(
1440-
":cross_mark: [red]The password used to decrypt your keyfile is invalid[/red]"
1441-
)
1442-
return False
1443-
except KeyFileError:
1444-
err_console.print(
1445-
":cross_mark: [red]Keyfile is corrupt, non-writable, or non-readable[/red]:"
1446-
)
1447-
return False
1448-
14491428
if not use_hotkey:
1450-
if not _unlock("coldkey"):
1429+
if not unlock_key(wallet, "coldkey").success:
14511430
return False
14521431
keypair = wallet.coldkey
14531432
print_verbose(
14541433
f"Signing using [{COLOR_PALETTE['GENERAL']['COLDKEY']}]coldkey: {wallet.name}"
14551434
)
14561435
else:
1457-
if not _unlock("hotkey"):
1436+
if not unlock_key(wallet, "hotkey").success:
14581437
return False
14591438
keypair = wallet.hotkey
14601439
print_verbose(

0 commit comments

Comments
 (0)