Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hotkey names for include/exclude in st add/remove #216

Merged
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
40 changes: 24 additions & 16 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3369,20 +3369,24 @@ def stake_add(
)

if include_hotkeys:
include_hotkeys = parse_to_list(
included_hotkeys = parse_to_list(
include_hotkeys,
str,
"Hotkeys must be a comma-separated list of ss58s, e.g., `--include-hotkeys 5Grw....,5Grw....`.",
is_ss58=True,
"Hotkeys must be a comma-separated list of ss58s or hotkey names, e.g., "
"`--include-hotkeys 5Grw....,5Grw....`.",
)
else:
included_hotkeys = []

if exclude_hotkeys:
exclude_hotkeys = parse_to_list(
excluded_hotkeys = parse_to_list(
exclude_hotkeys,
str,
"Hotkeys must be a comma-separated list of ss58s, e.g., `--exclude-hotkeys 5Grw....,5Grw....`.",
is_ss58=True,
"Hotkeys must be a comma-separated list of ss58s or hotkey names, e.g., "
"`--exclude-hotkeys 5Grw....,5Grw....`.",
)
else:
excluded_hotkeys = []

return self._run_command(
stake.stake_add(
Expand All @@ -3391,8 +3395,8 @@ def stake_add(
amount,
stake_all,
max_stake,
include_hotkeys,
exclude_hotkeys,
included_hotkeys,
excluded_hotkeys,
all_hotkeys,
prompt,
hotkey_ss58_address,
Expand Down Expand Up @@ -3524,29 +3528,33 @@ def stake_remove(
)

if include_hotkeys:
include_hotkeys = parse_to_list(
included_hotkeys = parse_to_list(
include_hotkeys,
str,
"Hotkeys must be a comma-separated list of ss58s, e.g., `--include-hotkeys 5Grw....,5Grw....`.",
is_ss58=True,
"Hotkeys must be a comma-separated list of ss58s or hotkey names, e.g., "
"`--include-hotkeys 5Grw....,5Grw....`.",
)
else:
included_hotkeys = []

if exclude_hotkeys:
exclude_hotkeys = parse_to_list(
excluded_hotkeys = parse_to_list(
exclude_hotkeys,
str,
"Hotkeys must be a comma-separated list of ss58s, e.g., `--exclude-hotkeys 5Grw....,5Grw....`.",
is_ss58=True,
"Hotkeys must be a comma-separated list of ss58s or hotkey names, e.g., "
"`--exclude-hotkeys 5Grw....,5Grw....`.",
)
else:
excluded_hotkeys = []

return self._run_command(
stake.unstake(
wallet,
self.initialize_chain(network),
hotkey_ss58_address,
all_hotkeys,
include_hotkeys,
exclude_hotkeys,
included_hotkeys,
excluded_hotkeys,
amount,
keep_stake,
unstake_all,
Expand Down
2 changes: 2 additions & 0 deletions bittensor_cli/src/commands/stake/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ async def is_hotkey_registered_any(hk: str, bh: str) -> bool:
(wallet.hotkey_str, wallet.hotkey.ss58_address)
for wallet in all_hotkeys_
if wallet.hotkey_str not in exclude_hotkeys
and wallet.hotkey.ss58_address not in exclude_hotkeys
] # definitely wallets

elif include_hotkeys:
Expand Down Expand Up @@ -1349,6 +1350,7 @@ async def unstake(
(wallet.hotkey_str, wallet.hotkey.ss58_address)
for wallet in all_hotkeys_
if wallet.hotkey_str not in exclude_hotkeys
and wallet.hotkey.ss58_address not in hotkeys_to_unstake_from
] # definitely wallets

elif include_hotkeys:
Expand Down
6 changes: 5 additions & 1 deletion bittensor_cli/src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,11 @@ async def overview(
de_registered_neurons.append(de_registered_neuron)

# Add this hotkey to the wallets dict
wallet_ = WalletLike(name=wallet.name, hotkey_ss58=hotkey_addr, hotkey_str=hotkey_addr[:5])
wallet_ = WalletLike(
name=wallet.name,
hotkey_ss58=hotkey_addr,
hotkey_str=hotkey_addr[:5],
)
# Indicates a hotkey not on local machine but exists in stake_info obj on-chain
if hotkey_coldkey_to_hotkey_wallet.get(hotkey_addr) is None:
hotkey_coldkey_to_hotkey_wallet[hotkey_addr] = {}
Expand Down
Loading