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

Fixes/Enhancements for wallets, faucet, network info #58

Merged
merged 1 commit into from
Sep 6, 2024
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
42 changes: 34 additions & 8 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,45 @@ class Options:
Re-usable typer args
"""

wallet_name = typer.Option(None, "--wallet-name", "-w", help="Name of wallet")
wallet_name = typer.Option(
None,
"--wallet-name",
"-w",
"--wallet_name",
"--wallet.name",
help="Name of wallet",
)
wallet_name_req = typer.Option(
None, "--wallet-name", "-w", "--wallet_name", help="Name of wallet", prompt=True
None,
"--wallet-name",
"-w",
"--wallet_name",
"--wallet.name",
help="Name of wallet",
prompt=True,
)
wallet_path = typer.Option(
None, "--wallet-path", "-p", "--wallet_path", help="Filepath of root of wallets"
None,
"--wallet-path",
"-p",
"--wallet_path",
"--wallet.path",
help="Filepath of root of wallets",
)
wallet_hotkey = typer.Option(
None, "--hotkey", "-H", "--wallet_hotkey", help="Hotkey of wallet"
None,
"--hotkey",
"-H",
"--wallet_hotkey",
"--wallet.hotkey",
help="Hotkey of wallet",
)
wallet_hk_req = typer.Option(
None,
"--hotkey",
"-H",
"--wallet_hotkey",
"--wallet.hotkey",
help="Hotkey name of wallet",
prompt=True,
)
Expand Down Expand Up @@ -1028,7 +1052,7 @@ def wallet_overview(
"[red]You have specified hotkeys for inclusion and exclusion. Pick only one or neither."
)
raise typer.Exit()
# if all-wallets is entered, ask for path

if all_wallets:
if not wallet_path:
wallet_path = Prompt.ask(
Expand Down Expand Up @@ -1228,13 +1252,13 @@ def wallet_faucet(
# TODO add the following to config
processors: Optional[int] = typer.Option(
defaults.pow_register.num_processes,
"-processors",
"--processors",
"-p",
help="Number of processors to use for POW registration.",
),
update_interval: Optional[int] = typer.Option(
defaults.pow_register.update_interval,
"-update-interval",
"--update-interval",
"-u",
help="The number of nonces to process before checking for next block during registration",
),
Expand Down Expand Up @@ -1671,7 +1695,9 @@ def wallet_history(
It helps in fetching info on all the transfers so that user can easily tally and cross-check the transactions.
"""
self.verbosity_handler(quiet, verbose)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
wallet = self.wallet_ask(
wallet_name, wallet_path, wallet_hotkey, validate=False
)
return self._run_command(wallets.wallet_history(wallet))

def wallet_set_id(
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def do_transfer() -> tuple[bool, str, str]:
f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {destination}[/bold white]"
)
return False

console.print(f"[dark_orange]Initiating transfer on network: {subtensor.network}")
# Unlock wallet coldkey.
wallet.unlock_coldkey()

Expand Down
23 changes: 18 additions & 5 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,30 @@
verbose_console = Console(quiet=True)


def print_console(message: str, colour: str, title: str, console: Console):
console.print(
f"[bold {colour}][{title}]:[/bold {colour}] [{colour}]{message}[/{colour}]\n"
)


def print_verbose(message: str, status=None):
"""Print verbose messages while temporarily pausing the status spinner."""
if status:
# Pause the spinner to avoid overlapping
status.stop()
verbose_console.print(
f"[bold green][Verbose]:[/bold green] [green]{message}[/green]\n"
)
print_console(message, "green", "Verbose", verbose_console)
status.start()
else:
print_console(message, "green", "Verbose", verbose_console)


def print_error(message: str, status=None):
"""Print error messages while temporarily pausing the status spinner."""
if status:
# Resume the spinner after the message is printed
status.stop()
print_console(message, "red", "Error", err_console)
status.start()
else:
print_console(message, "red", "Error", err_console)


RAO_PER_TAO = 1e9
Expand Down
48 changes: 33 additions & 15 deletions bittensor_cli/src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
convert_blocks_to_time,
decode_scale_bytes,
err_console,
print_error,
print_verbose,
get_all_wallets_for_path,
get_delegates_details_from_github,
Expand Down Expand Up @@ -249,7 +250,7 @@ async def wallet_balance(
style="green",
no_wrap=True,
),
title="[underline dark_orange]Wallet Coldkey Balances",
title=f"[underline dark_orange]Wallet Coldkey Balance[/underline dark_orange]\n\n[dark_orange]Network: {subtensor.network}",
show_footer=True,
show_edge=False,
border_style="bright_black",
Expand All @@ -268,7 +269,7 @@ async def wallet_balance(
)
table.add_row()
table.add_row(
"Total Balance Across All Coldkeys",
"Total Balance",
"",
str(total_free_balance),
str(total_staked_balance),
Expand Down Expand Up @@ -337,7 +338,7 @@ def create_transfer_history_table(transfers: list[dict]) -> Table:
box=box.SIMPLE,
pad_edge=False,
width=None,
title="[underline dark_orange]Wallet Transfers\n",
title="[underline dark_orange]Wallet Transfers[/underline dark_orange]\n\n[dark_orange]Network: finney",
)

table.add_column(
Expand Down Expand Up @@ -479,9 +480,13 @@ async def _get_total_balance(
)
).values()
)
all_hotkeys = [
hk for w in cold_wallets for hk in utils.get_hotkey_wallets_for_wallet(w)
]
all_hotkeys = []
for w in cold_wallets:
hotkeys_for_wallet = utils.get_hotkey_wallets_for_wallet(w)
if hotkeys_for_wallet:
all_hotkeys.extend(hotkeys_for_wallet)
else:
print_error(f"[red]No hotkeys found for wallet: ({w.name})")
else:
# We are only printing keys for a single coldkey
coldkey_wallet = wallet
Expand All @@ -500,6 +505,9 @@ async def _get_total_balance(
return [], None
all_hotkeys = utils.get_hotkey_wallets_for_wallet(coldkey_wallet)

if not all_hotkeys:
print_error(f"No hotkeys found for wallet ({coldkey_wallet.name})")

return all_hotkeys, total_balance


Expand All @@ -516,17 +524,18 @@ async def overview(
"""Prints an overview for the wallet's coldkey."""

total_balance = Balance(0)

# We are printing for every coldkey.
print_verbose("Fetching total balance for coldkey/s")
block_hash = await subtensor.substrate.get_chain_head()
all_hotkeys, total_balance = await _get_total_balance(
total_balance, subtensor, wallet, all_wallets
)

with console.status(
f":satellite: Synchronizing with chain [white]{subtensor.network}[/white]",
spinner="aesthetic",
) as status:
# We are printing for every coldkey.
print_verbose("Fetching total balance for hotkeys", status)
block_hash = await subtensor.substrate.get_chain_head()
all_hotkeys, total_balance = await _get_total_balance(
total_balance, subtensor, wallet, all_wallets
)

# We are printing for a select number of hotkeys from all_hotkeys.
if include_hotkeys:
print_verbose(
Expand All @@ -536,7 +545,7 @@ async def overview(

# Check we have keys to display.
if not all_hotkeys:
err_console.print("[red]No wallets found.[/red]")
print_error("Aborting as no hotkeys found to process", status)
return

# Pull neuron info for all keys.
Expand Down Expand Up @@ -669,6 +678,13 @@ async def overview(
title = "[underline dark_orange]All Wallets:[/underline dark_orange]"
grid.add_row(Align(title, vertical="middle", align="center"))

grid.add_row(
Align(
f"[dark_orange]Network: {subtensor.network}",
vertical="middle",
align="center",
)
)
# Generate rows per netuid
hotkeys_seen = set()
total_neurons = 0
Expand Down Expand Up @@ -1233,10 +1249,12 @@ def neuron_row_maker(
all_hotkeys = get_all_wallets_for_path(
wallet.path
) # TODO verify this is correct

else:
print_verbose(f"Fetching data for wallet: {wallet.name}")
wallets = [wallet]
all_hotkeys = get_hotkey_wallets_for_wallet(wallet)

with console.status("Synchronising with chain...", spinner="aesthetic") as status:
block_hash = await subtensor.substrate.get_chain_head()
await subtensor.substrate.init_runtime(block_hash=block_hash)
Expand Down Expand Up @@ -1268,7 +1286,7 @@ def neuron_row_maker(
Column("[bold white]Hotkey", style="bright_magenta"),
Column("[bold white]Stake", style="light_goldenrod2"),
Column("[bold white]Emission", style="rgb(42,161,152)"),
title="[underline dark_orange]Wallets\n",
title=f"[underline dark_orange]Wallets[/underline dark_orange]\n\n[dark_orange]Network: {subtensor.network}",
show_footer=True,
show_edge=False,
expand=True,
Expand Down
Loading