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

Adds improvements and minor fixes #112

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 39 additions & 11 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
from pathlib import Path
from typing import Coroutine, Optional
from dataclasses import fields

import rich
import typer
Expand All @@ -16,7 +17,6 @@
from rich.prompt import Confirm, FloatPrompt, Prompt, IntPrompt
from rich.table import Column, Table
from bittensor_cli.src import (
HYPERPARAMS,
defaults,
HELP_PANELS,
WalletOptions as WO,
Expand All @@ -30,6 +30,7 @@
from bittensor_cli.src.commands import weights as weights_cmds
from bittensor_cli.src.commands.stake import children_hotkeys, stake
from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface
from bittensor_cli.src.bittensor.chain_data import SubnetHyperparameters
from bittensor_cli.src.bittensor.utils import (
console,
err_console,
Expand Down Expand Up @@ -140,8 +141,9 @@ class Options:
netuids = typer.Option(
None,
"--netuids",
"--netuid",
"-n",
help="Set the netuid(s) to filter by. Separate multiple netuids with a comma, for example: `-n 0,1,2`.",
help="Set the netuid(s) to exclude. Separate multiple netuids with a comma, for example: `-n 0,1,2`.",
)
netuid = typer.Option(
None,
Expand Down Expand Up @@ -177,6 +179,9 @@ class Options:
prompt = typer.Option(
True,
"--prompt/--no-prompt",
" /--yes",
"--prompt/--no_prompt",
" /-y",
help="Enable or disable interactive prompts.",
)
verbose = typer.Option(
Expand Down Expand Up @@ -861,10 +866,22 @@ def set_config(
}
bools = ["use_cache"]
if all(v is None for v in args.values()):
arg = Prompt.ask(
"Which config setting would you like to update?",
choices=list(args.keys()),
# Print existing configs
self.get_config()

# Create numbering to choose from
config_keys = list(args.keys())
console.print("Which config setting would you like to update?\n")
for idx, key in enumerate(config_keys, start=1):
console.print(f"{idx}. {key}")

choice = IntPrompt.ask(
"\nEnter the [bold]number[/bold] of the config setting you want to update",
choices=[str(i) for i in range(1, len(config_keys) + 1)],
show_choices=False,
)
arg = config_keys[choice - 1]

if arg in bools:
nc = Confirm.ask(
f"What value would you like to assign to [red]{arg}[/red]?",
Expand Down Expand Up @@ -1721,6 +1738,11 @@ def wallet_new_hotkey(
"""
self.verbosity_handler(quiet, verbose)

if not wallet_name:
wallet_name = Prompt.ask(
"Enter the wallet name", default=defaults.wallet.name
)

if not wallet_hotkey:
wallet_hotkey = Prompt.ask(
"Enter the name of the new hotkey", default=defaults.wallet.hotkey
Expand Down Expand Up @@ -2173,7 +2195,13 @@ def root_set_weights(
wallet_name: str = Options.wallet_name,
wallet_path: str = Options.wallet_path,
wallet_hotkey: str = Options.wallet_hotkey,
netuids: str = Options.netuids,
netuids=typer.Option(
None,
"--netuids",
"--netuid",
"-n",
help="Set the netuid(s) to set weights to. Separate multiple netuids with a comma, for example: `-n 0,1,2`.",
),
weights: str = Options.weights,
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
Expand Down Expand Up @@ -3067,7 +3095,7 @@ def stake_add(
):
hotkey_or_ss58 = Prompt.ask(
"Do you want to stake to a specific [blue]ss58 address[/blue] or a registered [red]wallet hotkey[/red]?\n"
"[Enter '[blue]ss58[/blue]' for an address or '[red]hotkey[/red]' for a wallet hotkey] (default is '[blue]ss58[/blue]')",
"[Enter '[blue]ss58[/blue]' for an address or '[red]hotkey[/red]' for a wallet hotkey] (default is '[red]hotkey[/red]')",
choices=["ss58", "hotkey"],
default="hotkey",
show_choices=False,
Expand Down Expand Up @@ -3232,9 +3260,9 @@ def stake_remove(
"Do you want to unstake from a specific [blue]ss58 address[/blue] or a registered [red]wallet hotkey"
"[/red]?\n"
"[Enter '[blue]ss58[/blue]' for an address or '[red]hotkey[/red]' for a wallet hotkey] (default is "
"'[blue]ss58[/blue]')",
"'[red]hotkey[/red]')",
choices=["ss58", "hotkey"],
default="ss58",
default="hotkey",
show_choices=False,
show_default=False,
)
Expand Down Expand Up @@ -3631,7 +3659,7 @@ def sudo_set(
raise typer.Exit()

if not param_name:
hyperparam_list = list(HYPERPARAMS.keys())
hyperparam_list = [field.name for field in fields(SubnetHyperparameters)]
console.print("Available hyperparameters:\n")
for idx, param in enumerate(hyperparam_list, start=1):
console.print(f" {idx}. {param}")
Expand Down Expand Up @@ -4024,7 +4052,7 @@ def weights_reveal(
None,
"--salt",
"-s",
help="Corresponding salt for the hash function, e.g. -s 163 -s 241 -s 217 ...",
help="Corresponding salt for the hash function, e.g. -s 163,241,217 ...",
),
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down
12 changes: 10 additions & 2 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,18 @@ async def filter_netuids_by_registered_hotkeys(
all_netuids = netuids_with_registered_hotkeys

else:
all_netuids = [
filtered_netuids = [
netuid for netuid in all_netuids if netuid in filter_for_netuids
]
all_netuids.extend(netuids_with_registered_hotkeys)

registered_hotkeys_filtered = [
netuid
for netuid in netuids_with_registered_hotkeys
if netuid in filter_for_netuids
]

# Combine both filtered lists
all_netuids = filtered_netuids + registered_hotkeys_filtered

return list(set(all_netuids))

Expand Down
105 changes: 62 additions & 43 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,58 +719,72 @@ async def _get_list() -> tuple:
)
return sm, rn, di, ts

table = Table(
Column(
"[bold white]UID",
style="dark_orange",
no_wrap=True,
),
Column(
"[bold white]NAME",
style="bright_cyan",
no_wrap=True,
),
Column(
"[bold white]ADDRESS",
style="bright_magenta",
no_wrap=True,
),
Column(
"[bold white]STAKE(\u03c4)",
justify="right",
style="light_goldenrod2",
no_wrap=True,
),
Column(
"[bold white]SENATOR",
style="dark_sea_green",
no_wrap=True,
),
title=f"[underline dark_orange]Root Network[/underline dark_orange]\n[dark_orange]Network {subtensor.network}",
show_footer=True,
show_edge=False,
expand=False,
border_style="bright_black",
)

with console.status(
f":satellite: Syncing with chain: [white]{subtensor}[/white] ...",
spinner="aesthetic",
):

senate_members, root_neurons, delegate_info, total_stakes = await _get_list()
total_tao = sum(float(Balance.from_rao(total_stakes[neuron.hotkey])) for neuron in root_neurons)

if not root_neurons:
err_console.print(
f"[red]Error: No neurons detected on network:[/red] [white]{subtensor}"
table = Table(
Column(
"[bold white]UID",
style="dark_orange",
no_wrap=True,
footer=f"[bold]{len(root_neurons)}[/bold]"
),
Column(
"[bold white]NAME",
style="bright_cyan",
no_wrap=True,
),
Column(
"[bold white]ADDRESS",
style="bright_magenta",
no_wrap=True,
),
Column(
"[bold white]STAKE(\u03c4)",
justify="right",
style="light_goldenrod2",
no_wrap=True,
footer=f"{total_tao:.2f} (\u03c4) "
),
Column(
"[bold white]SENATOR",
style="dark_sea_green",
no_wrap=True,
),
title=f"[underline dark_orange]Root Network[/underline dark_orange]\n[dark_orange]Network {subtensor.network}",
rajkaramchedu marked this conversation as resolved.
Show resolved Hide resolved
show_footer=True,
show_edge=False,
expand=False,
border_style="bright_black",
leading=True,
)


if not root_neurons:
err_console.print(
f"[red]Error: No neurons detected on network:[/red] [white]{subtensor}"
ibraheem-opentensor marked this conversation as resolved.
Show resolved Hide resolved
)
raise typer.Exit()

sorted_root_neurons = sorted(
root_neurons,
key=lambda neuron: float(Balance.from_rao(total_stakes[neuron.hotkey])),
reverse=True,
)
raise typer.Exit()

for neuron_data in root_neurons:
for neuron_data in sorted_root_neurons:
table.add_row(
str(neuron_data.uid),
(
delegate_info[neuron_data.hotkey].display
if neuron_data.hotkey in delegate_info
else ""
else "~"
),
neuron_data.hotkey,
"{:.5f}".format(float(Balance.from_rao(total_stakes[neuron_data.hotkey]))),
Expand Down Expand Up @@ -1124,14 +1138,15 @@ async def get_senate(subtensor: SubtensorInterface):
show_edge=False,
expand=False,
border_style="bright_black",
leading=True,
)

for ss58_address in senate_members:
table.add_row(
(
delegate_info[ss58_address].display
if ss58_address in delegate_info
else ""
else "~"
),
ss58_address,
)
Expand Down Expand Up @@ -1375,7 +1390,7 @@ async def wallet_to_delegates(
style="bright_magenta",
justify="left",
overflow="fold",
ratio=2,
ratio=3,
),
Column("[white]Delegation", style="dark_orange", no_wrap=True, ratio=1),
Column("[white]\u03c4/24h", style="bold green", ratio=1),
Expand Down Expand Up @@ -1405,13 +1420,14 @@ async def wallet_to_delegates(
Column(
"[white]24h/k\u03c4", style="rgb(42,161,152)", justify="center", ratio=1
),
Column("[white]Desc", style="rgb(50,163,219)", ratio=2),
Column("[white]Desc", style="rgb(50,163,219)", ratio=3),
title=f"[underline dark_orange]My Delegates[/underline dark_orange]\n[dark_orange]Network: {subtensor.network}\n",
rajkaramchedu marked this conversation as resolved.
Show resolved Hide resolved
show_footer=True,
show_edge=False,
expand=False,
box=box.SIMPLE_HEAVY,
border_style="bright_black",
leading=True,
)

total_delegated = 0
Expand Down Expand Up @@ -1488,7 +1504,10 @@ async def wallet_to_delegates(
f"{delegate[0].total_daily_return.tao * (1000 / (0.001 + delegate[0].total_stake.tao))!s:6.6}",
str(delegate_description),
)

if console.width < 150:
console.print(
"[yellow]Warning: Your terminal width might be too small to view all information clearly"
ibraheem-opentensor marked this conversation as resolved.
Show resolved Hide resolved
)
console.print(table)
console.print(f"Total delegated Tao: {total_delegated}")
ibraheem-opentensor marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
8 changes: 5 additions & 3 deletions bittensor_cli/src/commands/stake/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,15 @@ async def get_all_wallet_accounts(
total_balance += cast(Balance, acc["balance"]).tao
for key, value in cast(dict, acc["accounts"]).items():
if value["name"] and value["name"] != key:
account_display_name = f"[bright_cyan]({value['name']})[/bright_cyan] [bright_magenta]{key}[/bright_magenta]"
account_display_name = f"{value['name']}"
else:
account_display_name = f"[bright_cyan](~)[/bright_cyan] [bright_magenta]{key}[/bright_magenta]"
account_display_name = "(~)"
rows.append(
[
"",
"",
account_display_name,
key,
str(value["stake"]),
str(value["rate"]),
]
Expand Down Expand Up @@ -1092,7 +1093,8 @@ async def get_all_wallet_accounts(
style="dark_sea_green",
ratio=1,
),
Column("[bold white]Hotkey", ratio=7, no_wrap=True),
Column("[bold white]Account", style="bright_cyan", ratio=3),
Column("[bold white]Hotkey", ratio=7, no_wrap=True, style="bright_magenta"),
Column(
"[bold white]Stake",
metadata["total_stake"],
Expand Down
Loading