diff --git a/bittensor/cli.py b/bittensor/cli.py index 1d1ef56561..673fa31419 100644 --- a/bittensor/cli.py +++ b/bittensor/cli.py @@ -65,6 +65,7 @@ "commands": { "list": RootList, "weights": RootSetWeightsCommand, + "get_weights": RootGetWeightsCommand, "senate_vote": VoteCommand, "register": RootRegisterCommand, "proposals": ProposalsCommand, diff --git a/bittensor/commands/__init__.py b/bittensor/commands/__init__.py index f48d0bb3bf..b9e7721547 100644 --- a/bittensor/commands/__init__.py +++ b/bittensor/commands/__init__.py @@ -103,4 +103,9 @@ SubnetHyperparamsCommand, SubnetGetHyperparamsCommand, ) -from .root import RootRegisterCommand, RootList, RootSetWeightsCommand +from .root import ( + RootRegisterCommand, + RootList, + RootSetWeightsCommand, + RootGetWeightsCommand, +) diff --git a/bittensor/commands/root.py b/bittensor/commands/root.py index 427e91e2b7..0886a032de 100644 --- a/bittensor/commands/root.py +++ b/bittensor/commands/root.py @@ -210,3 +210,62 @@ def check_config(config: "bittensor.config"): if not config.is_set("wallet.hotkey") and not config.no_prompt: hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey) config.wallet.hotkey = str(hotkey) + + +class RootGetWeightsCommand: + @staticmethod + def run(cli): + r"""Get weights for root network.""" + subtensor = bittensor.subtensor(config=cli.config) + weights = subtensor.weights(0) + + table = Table(show_footer=False) + table.title = "[white]Root Network Weights" + table.add_column( + "[overline white]UID", + footer_style="overline white", + style="rgb(50,163,219)", + no_wrap=True, + ) + table.add_column( + "[overline white]NETUID", + footer_style="overline white", + justify="right", + style="green", + no_wrap=True, + ) + table.add_column( + "[overline white]WEIGHT", + footer_style="overline white", + justify="right", + style="green", + no_wrap=True, + ) + table.show_footer = True + + for matrix in weights: + uid = matrix[0] + for weight_data in matrix[1]: + table.add_row( + str(uid), + str(weight_data[0]), + "{:0.2f}%".format((weight_data[1] / 65535) * 100), + ) + + table.box = None + table.pad_edge = False + table.width = None + bittensor.__console__.print(table) + + @staticmethod + def add_args(parser: argparse.ArgumentParser): + parser = parser.add_parser( + "get_weights", help="""Get weights for root network.""" + ) + + bittensor.wallet.add_args(parser) + bittensor.subtensor.add_args(parser) + + @staticmethod + def check_config(config: "bittensor.config"): + pass