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
50 changes: 43 additions & 7 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from bittensor_cli.src.bittensor import utils
from bittensor_cli.src.bittensor.balances import Balance
from async_substrate_interface.errors import SubstrateRequestException
from bittensor_cli.src.commands import sudo, wallets
from bittensor_cli.src.commands import sudo, wallets, view
from bittensor_cli.src.commands import weights as weights_cmds
from bittensor_cli.src.commands.subnets import price, subnets
from bittensor_cli.src.commands.stake import (
Expand Down Expand Up @@ -193,8 +193,7 @@ class Options:
)
wait_for_finalization = typer.Option(
True,
help="If `True`, waits until the transaction is finalized "
"on the blockchain.",
help="If `True`, waits until the transaction is finalized on the blockchain.",
)
prompt = typer.Option(
True,
Expand Down Expand Up @@ -513,6 +512,7 @@ class CLIManager:
subnets_app: typer.Typer
weights_app: typer.Typer
utils_app = typer.Typer(epilog=_epilog)
view_app: typer.Typer
asyncio_runner = asyncio

def __init__(self):
Expand Down Expand Up @@ -562,6 +562,7 @@ def __init__(self):
self.sudo_app = typer.Typer(epilog=_epilog)
self.subnets_app = typer.Typer(epilog=_epilog)
self.weights_app = typer.Typer(epilog=_epilog)
self.view_app = typer.Typer(epilog=_epilog)

# config alias
self.app.add_typer(
Expand Down Expand Up @@ -639,6 +640,14 @@ def __init__(self):
self.utils_app, name="utils", no_args_is_help=True, hidden=True
)

# view app
self.app.add_typer(
self.view_app,
name="view",
short_help="HTML view commands",
no_args_is_help=True,
)

# config commands
self.config_app.command("set")(self.set_config)
self.config_app.command("get")(self.get_config)
Expand Down Expand Up @@ -806,6 +815,11 @@ def __init__(self):
"commit", rich_help_panel=HELP_PANELS["WEIGHTS"]["COMMIT_REVEAL"]
)(self.weights_commit)

# view commands
self.view_app.command(
"dashboard", rich_help_panel=HELP_PANELS["VIEW"]["DASHBOARD"]
)(self.view_dashboard)

# Sub command aliases
# Weights
self.wallet_app.command(
Expand Down Expand Up @@ -1336,7 +1350,7 @@ def get_config(self):
if value in Constants.networks:
value = value + f" ({Constants.network_map[value]})"
if key == "rate_tolerance":
value = f"{value} ({value*100}%)" if value is not None else "None"
value = f"{value} ({value * 100}%)" if value is not None else "None"

elif key in deprecated_configs:
continue
Expand Down Expand Up @@ -1365,19 +1379,19 @@ def ask_rate_tolerance(
"""
if rate_tolerance is not None:
console.print(
f"[dim][blue]Rate tolerance[/blue]: [bold cyan]{rate_tolerance} ({rate_tolerance*100}%)[/bold cyan]."
f"[dim][blue]Rate tolerance[/blue]: [bold cyan]{rate_tolerance} ({rate_tolerance * 100}%)[/bold cyan]."
)
return rate_tolerance
elif self.config.get("rate_tolerance") is not None:
config_slippage = self.config["rate_tolerance"]
console.print(
f"[dim][blue]Rate tolerance[/blue]: [bold cyan]{config_slippage} ({config_slippage*100}%)[/bold cyan] (from config)."
f"[dim][blue]Rate tolerance[/blue]: [bold cyan]{config_slippage} ({config_slippage * 100}%)[/bold cyan] (from config)."
)
return config_slippage
else:
console.print(
"[dim][blue]Rate tolerance[/blue]: "
+ f"[bold cyan]{defaults.rate_tolerance} ({defaults.rate_tolerance*100}%)[/bold cyan] "
+ f"[bold cyan]{defaults.rate_tolerance} ({defaults.rate_tolerance * 100}%)[/bold cyan] "
+ "by default. Set this using "
+ "[dark_sea_green3 italic]`btcli config set`[/dark_sea_green3 italic] "
+ "or "
Expand Down Expand Up @@ -5071,6 +5085,28 @@ def weights_commit(
)
)

def view_dashboard(
self,
network: Optional[list[str]] = Options.network,
wallet_name: str = Options.wallet_name,
wallet_path: str = Options.wallet_path,
wallet_hotkey: str = Options.wallet_hotkey,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
):
"""
Display html dashboard with subnets list, stake, and neuron information.
"""
self.verbosity_handler(quiet, verbose)
if is_linux():
print_linux_dependency_message()
wallet = self.wallet_ask(
wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH]
)
return self._run_command(
view.display_network_dashboard(wallet, self.initialize_chain(network))
)

@staticmethod
@utils_app.command("convert")
def convert(
Expand Down
3 changes: 3 additions & 0 deletions bittensor_cli/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ class WalletValidationTypes(Enum):
"IDENTITY": "Subnet Identity Management",
},
"WEIGHTS": {"COMMIT_REVEAL": "Commit / Reveal"},
"VIEW": {
"DASHBOARD": "Network Dashboard",
},
}

COLOR_PALETTE = {
Expand Down
11 changes: 5 additions & 6 deletions bittensor_cli/src/bittensor/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,16 @@ def set_unit(self, netuid: int):
return self


def fixed_to_float(fixed: dict) -> float:
# Currently this is stored as a U64F64
def fixed_to_float(fixed, frac_bits: int = 64, total_bits: int = 128) -> float:
# By default, this is a U64F64
# which is 64 bits of integer and 64 bits of fractional
# uint_bits = 64
frac_bits = 64

data: int = fixed["bits"]

# Shift bits to extract integer part (assuming 64 bits for integer part)
integer_part = data >> frac_bits
# Logical and to get the fractional part; remaining is the integer part
fractional_part = data & (2**frac_bits - 1)
# Shift to get the integer part from the remaining bits
integer_part = data >> (total_bits - frac_bits)

frac_float = fractional_part / (2**frac_bits)

Expand Down
Loading
Loading