Skip to content

Commit d3ed955

Browse files
authored
Merge branch 'staging' into feat/thewhaleking/bump-versions
2 parents 2596878 + be873ff commit d3ed955

22 files changed

+1617
-577
lines changed

bittensor_cli/cli.py

Lines changed: 247 additions & 117 deletions
Large diffs are not rendered by default.

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ def tao_to_alpha_with_slippage(
749749
self, tao: Balance
750750
) -> tuple[Balance, Balance, float]:
751751
"""
752-
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool state.
752+
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool
753+
state.
754+
753755
Args:
754756
tao: Amount of TAO to stake.
755757
Returns:
@@ -792,7 +794,9 @@ def alpha_to_tao_with_slippage(
792794
self, alpha: Balance
793795
) -> tuple[Balance, Balance, float]:
794796
"""
795-
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool state.
797+
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool
798+
state.
799+
796800
Args:
797801
alpha: Amount of Alpha to stake.
798802
Returns:

bittensor_cli/src/bittensor/extrinsics/registration.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ async def get_neuron_for_pubkey_and_subnet():
524524
if prompt:
525525
if not Confirm.ask(
526526
f"Continue Registration?\n"
527-
f" hotkey [{COLOR_PALETTE['GENERAL']['HOTKEY']}]({wallet.hotkey_str})[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]:\t[{COLOR_PALETTE['GENERAL']['HOTKEY']}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
528-
f" coldkey [{COLOR_PALETTE['GENERAL']['COLDKEY']}]({wallet.name})[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]:\t[{COLOR_PALETTE['GENERAL']['COLDKEY']}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]\n"
529-
f" network:\t\t[{COLOR_PALETTE['GENERAL']['LINKS']}]{subtensor.network}[/{COLOR_PALETTE['GENERAL']['LINKS']}]\n"
527+
f" hotkey [{COLOR_PALETTE.G.HK}]({wallet.hotkey_str})[/{COLOR_PALETTE.G.HK}]:"
528+
f"\t[{COLOR_PALETTE.G.HK}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE.G.HK}]\n"
529+
f" coldkey [{COLOR_PALETTE.G.CK}]({wallet.name})[/{COLOR_PALETTE.G.CK}]:"
530+
f"\t[{COLOR_PALETTE.G.CK}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE.G.CK}]\n"
531+
f" network:\t\t[{COLOR_PALETTE.G.LINKS}]{subtensor.network}[/{COLOR_PALETTE.G.LINKS}]\n"
530532
):
531533
return False
532534

@@ -611,7 +613,6 @@ async def get_neuron_for_pubkey_and_subnet():
611613
if not wait_for_finalization and not wait_for_inclusion:
612614
success, err_msg = True, ""
613615
else:
614-
await response.process_events()
615616
success = await response.is_success
616617
if not success:
617618
success, err_msg = (
@@ -678,7 +679,7 @@ async def burned_register_extrinsic(
678679
wait_for_finalization: bool = True,
679680
era: Optional[int] = None,
680681
prompt: bool = False,
681-
) -> bool:
682+
) -> tuple[bool, str]:
682683
"""Registers the wallet to chain by recycling TAO.
683684
684685
:param subtensor: The SubtensorInterface object to use for the call, initialized
@@ -689,10 +690,11 @@ async def burned_register_extrinsic(
689690
`False` if the extrinsic fails to enter the block within the timeout.
690691
:param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning `True`,
691692
or returns `False` if the extrinsic fails to be finalized within the timeout.
693+
:param era: the period (in blocks) for which the transaction should remain valid.
692694
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
693695
694-
:return: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
695-
finalization/inclusion, the response is `True`.
696+
:return: (success, msg), where success is `True` if extrinsic was finalized or included in the block. If we did not
697+
wait for finalization/inclusion, the response is `True`.
696698
"""
697699

698700
if not (unlock_status := unlock_key(wallet, print_out=False)).success:
@@ -735,12 +737,12 @@ async def burned_register_extrinsic(
735737
if not neuron.is_null:
736738
console.print(
737739
":white_heavy_check_mark: [dark_sea_green3]Already Registered[/dark_sea_green3]:\n"
738-
f"uid: [{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]{neuron.uid}[/{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]\n"
739-
f"netuid: [{COLOR_PALETTE['GENERAL']['NETUID']}]{neuron.netuid}[/{COLOR_PALETTE['GENERAL']['NETUID']}]\n"
740-
f"hotkey: [{COLOR_PALETTE['GENERAL']['HOTKEY']}]{neuron.hotkey}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
741-
f"coldkey: [{COLOR_PALETTE['GENERAL']['COLDKEY']}]{neuron.coldkey}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]"
740+
f"uid: [{COLOR_PALETTE.G.NETUID_EXTRA}]{neuron.uid}[/{COLOR_PALETTE.G.NETUID_EXTRA}]\n"
741+
f"netuid: [{COLOR_PALETTE.G.NETUID}]{neuron.netuid}[/{COLOR_PALETTE.G.NETUID}]\n"
742+
f"hotkey: [{COLOR_PALETTE.G.HK}]{neuron.hotkey}[/{COLOR_PALETTE.G.HK}]\n"
743+
f"coldkey: [{COLOR_PALETTE.G.CK}]{neuron.coldkey}[/{COLOR_PALETTE.G.CK}]"
742744
)
743-
return True
745+
return True, "Already registered"
744746

745747
with console.status(
746748
":satellite: Recycling TAO for Registration...", spinner="aesthetic"
@@ -760,7 +762,7 @@ async def burned_register_extrinsic(
760762
if not success:
761763
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
762764
await asyncio.sleep(0.5)
763-
return False
765+
return False, err_msg
764766
# Successful registration, final check for neuron and pubkey
765767
else:
766768
with console.status(":satellite: Checking Balance...", spinner="aesthetic"):
@@ -781,20 +783,21 @@ async def burned_register_extrinsic(
781783

782784
console.print(
783785
"Balance:\n"
784-
f" [blue]{old_balance}[/blue] :arrow_right: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
786+
f" [blue]{old_balance}[/blue] :arrow_right: "
787+
f"[{COLOR_PALETTE.S.STAKE_AMOUNT}]{new_balance}[/{COLOR_PALETTE.S.STAKE_AMOUNT}]"
785788
)
786789

787790
if len(netuids_for_hotkey) > 0:
788791
console.print(
789792
f":white_heavy_check_mark: [green]Registered on netuid {netuid} with UID {my_uid}[/green]"
790793
)
791-
return True
794+
return True, f"Registered on {netuid} with UID {my_uid}"
792795
else:
793796
# neuron not found, try again
794797
err_console.print(
795798
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
796799
)
797-
return False
800+
return False, "Unknown error. Neuron not found."
798801

799802

800803
async def run_faucet_extrinsic(
@@ -914,7 +917,6 @@ async def run_faucet_extrinsic(
914917
)
915918

916919
# process if registration successful, try again if pow is still valid
917-
await response.process_events()
918920
if not await response.is_success:
919921
err_console.print(
920922
f":cross_mark: [red]Failed[/red]: "
@@ -1757,7 +1759,8 @@ async def swap_hotkey_extrinsic(
17571759
)
17581760
if not len(netuids_registered) > 0:
17591761
err_console.print(
1760-
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. Please register and try again"
1762+
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. "
1763+
f"Please register and try again"
17611764
)
17621765
return False
17631766

@@ -1774,7 +1777,8 @@ async def swap_hotkey_extrinsic(
17741777
):
17751778
return False
17761779
print_verbose(
1777-
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with {new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
1780+
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with "
1781+
f"{new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
17781782
)
17791783
with console.status(":satellite: Swapping hotkeys...", spinner="aesthetic"):
17801784
call = await subtensor.substrate.compose_call(

bittensor_cli/src/bittensor/extrinsics/root.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async def root_register_extrinsic(
291291
wait_for_inclusion: bool = True,
292292
wait_for_finalization: bool = True,
293293
prompt: bool = False,
294-
) -> bool:
294+
) -> tuple[bool, str]:
295295
r"""Registers the wallet to root network.
296296
297297
:param subtensor: The SubtensorInterface object
@@ -302,12 +302,12 @@ async def root_register_extrinsic(
302302
or returns `False` if the extrinsic fails to be finalized within the timeout.
303303
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
304304
305-
:return: `True` if extrinsic was finalized or included in the block. If we did not wait for finalization/inclusion,
306-
the response is `True`.
305+
:return: (success, msg), with success being `True` if extrinsic was finalized or included in the block. If we did
306+
not wait for finalization/inclusion, the response is `True`.
307307
"""
308308

309-
if not unlock_key(wallet).success:
310-
return False
309+
if not (unlock := unlock_key(wallet)).success:
310+
return False, unlock.message
311311

312312
print_verbose(f"Checking if hotkey ({wallet.hotkey_str}) is registered on root")
313313
is_registered = await is_hotkey_registered(
@@ -317,7 +317,7 @@ async def root_register_extrinsic(
317317
console.print(
318318
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
319319
)
320-
return True
320+
return True, "Already registered on root network"
321321

322322
with console.status(":satellite: Registering to root network...", spinner="earth"):
323323
call = await subtensor.substrate.compose_call(
@@ -334,8 +334,8 @@ async def root_register_extrinsic(
334334

335335
if not success:
336336
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
337-
time.sleep(0.5)
338-
return False
337+
await asyncio.sleep(0.5)
338+
return False, err_msg
339339

340340
# Successful registration, final check for neuron and pubkey
341341
else:
@@ -348,13 +348,13 @@ async def root_register_extrinsic(
348348
console.print(
349349
f":white_heavy_check_mark: [green]Registered with UID {uid}[/green]"
350350
)
351-
return True
351+
return True, f"Registered with UID {uid}"
352352
else:
353353
# neuron not found, try again
354354
err_console.print(
355355
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
356356
)
357-
return False
357+
return False, "Unknown error. Neuron not found."
358358

359359

360360
async def set_root_weights_extrinsic(
@@ -410,7 +410,6 @@ async def _do_set_weights():
410410
if not wait_for_finalization and not wait_for_inclusion:
411411
return True, "Not waiting for finalization or inclusion."
412412

413-
await response.process_events()
414413
if await response.is_success:
415414
return True, "Successfully set weights."
416415
else:

bittensor_cli/src/bittensor/extrinsics/transfer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async def transfer_extrinsic(
3737
:param wallet: Bittensor wallet object to make transfer from.
3838
:param destination: Destination public key address (ss58_address or ed25519) of recipient.
3939
:param amount: Amount to stake as Bittensor balance.
40+
:param era: Length (in blocks) for which the transaction should be valid.
4041
:param transfer_all: Whether to transfer all funds from this wallet to the destination address.
4142
:param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`,
4243
or returns `False` if the extrinsic fails to enter the block within the timeout.
@@ -97,7 +98,6 @@ async def do_transfer() -> tuple[bool, str, str]:
9798
return True, "", ""
9899

99100
# Otherwise continue with finalization.
100-
await response.process_events()
101101
if await response.is_success:
102102
block_hash_ = response.block_hash
103103
return True, block_hash_, ""
@@ -156,7 +156,8 @@ async def do_transfer() -> tuple[bool, str, str]:
156156
if not Confirm.ask(
157157
"Do you want to transfer:[bold white]\n"
158158
f" amount: [bright_cyan]{amount}[/bright_cyan]\n"
159-
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : [bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
159+
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : "
160+
f"[bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
160161
f" to: [bright_magenta]{destination}[/bright_magenta]\n for fee: [bright_cyan]{fee}[/bright_cyan]"
161162
):
162163
return False

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ async def sign_and_send_extrinsic(
10571057
:param wallet: the wallet whose coldkey will be used to sign the extrinsic
10581058
:param wait_for_inclusion: whether to wait until the extrinsic call is included on the chain
10591059
:param wait_for_finalization: whether to wait until the extrinsic call is finalized on the chain
1060+
:param era: The length (in blocks) for which a transaction should be valid.
10601061
10611062
:return: (success, error message)
10621063
"""
@@ -1075,7 +1076,6 @@ async def sign_and_send_extrinsic(
10751076
# We only wait here if we expect finalization.
10761077
if not wait_for_finalization and not wait_for_inclusion:
10771078
return True, ""
1078-
await response.process_events()
10791079
if await response.is_success:
10801080
return True, ""
10811081
else:
@@ -1372,11 +1372,11 @@ async def get_stake_for_coldkeys(
13721372
This function is useful for analyzing the stake distribution and delegation patterns of multiple
13731373
accounts simultaneously, offering a broader perspective on network participation and investment strategies.
13741374
"""
1375-
BATCH_SIZE = 60
1375+
batch_size = 60
13761376

13771377
tasks = []
1378-
for i in range(0, len(coldkey_ss58_list), BATCH_SIZE):
1379-
ss58_chunk = coldkey_ss58_list[i : i + BATCH_SIZE]
1378+
for i in range(0, len(coldkey_ss58_list), batch_size):
1379+
ss58_chunk = coldkey_ss58_list[i : i + batch_size]
13801380
tasks.append(
13811381
self.query_runtime_api(
13821382
runtime_api="StakeInfoRuntimeApi",

bittensor_cli/src/bittensor/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from bittensor_cli.src.bittensor.chain_data import SubnetHyperparameters
3434

3535
console = Console()
36+
json_console = Console()
3637
err_console = Console(stderr=True)
3738
verbose_console = Console(quiet=True)
3839

@@ -1052,6 +1053,7 @@ def get_effective_network(config, network: Optional[list[str]]) -> str:
10521053
the configuration, and the default.
10531054
"""
10541055
if network:
1056+
network_ = ""
10551057
for item in network:
10561058
if item.startswith("ws"):
10571059
network_ = item
@@ -1308,7 +1310,8 @@ def print_linux_dependency_message():
13081310
"\tAdd this into the file and save: [green]deb http://archive.ubuntu.com/ubuntu jammy main universe[/green]"
13091311
)
13101312
console.print(
1311-
"\tUpdate the repository and install the webkit dependency: [green]sudo apt update && sudo apt install libwebkit2gtk-4.0-dev[/green]"
1313+
"\tUpdate the repository and install the webkit dependency: [green]sudo apt update && sudo apt install "
1314+
"libwebkit2gtk-4.0-dev[/green]"
13121315
)
13131316
console.print("\nFedora / CentOS / AlmaLinux:")
13141317
console.print("[green]sudo dnf install gtk3-devel webkit2gtk3-devel[/green]\n\n")

0 commit comments

Comments
 (0)