diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 64202e17a..3fe783a5f 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -26,6 +26,7 @@ Constants, ) from bittensor_cli.src.bittensor import utils +from bittensor_cli.src.bittensor.balances import Balance from bittensor_cli.src.bittensor.async_substrate_interface import ( SubstrateRequestException, ) @@ -400,6 +401,7 @@ class CLIManager: root_app: typer.Typer subnets_app: typer.Typer weights_app: typer.Typer + utils_app = typer.Typer(epilog=_epilog) def __init__(self): self.config = { @@ -524,6 +526,9 @@ def __init__(self): self.weights_app, name="weight", hidden=True, no_args_is_help=True ) + # utils app + self.app.add_typer(self.utils_app, name="utils", no_args_is_help=True) + # config commands self.config_app.command("set")(self.set_config) self.config_app.command("get")(self.get_config) @@ -4333,6 +4338,37 @@ def weights_commit( ) ) + @staticmethod + @utils_app.command("convert") + def convert( + from_rao: Optional[str] = typer.Option( + None, "--rao", help="Convert amount from Rao" + ), + from_tao: Optional[float] = typer.Option( + None, "--tao", help="Convert amount from Tao" + ), + ): + """ + Allows for converting between tao and rao using the specified flags + """ + if from_tao is None and from_rao is None: + err_console.print("Specify `--rao` and/or `--tao`.") + raise typer.Exit() + if from_rao is not None: + rao = int(float(from_rao)) + console.print( + f"{rao}{Balance.rao_unit}", + "=", + Balance.from_rao(rao), + ) + if from_tao is not None: + tao = float(from_tao) + console.print( + f"{Balance.unit}{tao}", + "=", + f"{Balance.from_tao(tao).rao}{Balance.rao_unit}", + ) + def run(self): self.app()