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
51 changes: 35 additions & 16 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4379,7 +4379,7 @@ def stake_move(
f"interactive_selection: {interactive_selection}\n"
f"prompt: {prompt}\n"
)
result = self._run_command(
result, ext_id = self._run_command(
move_stake.move_stake(
subtensor=self.initialize_chain(network),
wallet=wallet,
Expand All @@ -4395,7 +4395,9 @@ def stake_move(
)
)
if json_output:
json_console.print(json.dumps({"success": result}))
json_console.print(
json.dumps({"success": result, "extrinsic_identifier": ext_id or None})
)
return result

def stake_transfer(
Expand Down Expand Up @@ -4555,7 +4557,7 @@ def stake_transfer(
f"era: {period}\n"
f"stake_all: {stake_all}"
)
result = self._run_command(
result, ext_id = self._run_command(
move_stake.transfer_stake(
wallet=wallet,
subtensor=self.initialize_chain(network),
Expand All @@ -4571,7 +4573,9 @@ def stake_transfer(
)
)
if json_output:
json_console.print(json.dumps({"success": result}))
json_console.print(
json.dumps({"success": result, "extrinsic_identifier": ext_id or None})
)
return result

def stake_swap(
Expand Down Expand Up @@ -4675,7 +4679,7 @@ def stake_swap(
f"wait_for_inclusion: {wait_for_inclusion}\n"
f"wait_for_finalization: {wait_for_finalization}\n"
)
result = self._run_command(
result, ext_id = self._run_command(
move_stake.swap_stake(
wallet=wallet,
subtensor=self.initialize_chain(network),
Expand All @@ -4691,7 +4695,9 @@ def stake_swap(
)
)
if json_output:
json_console.print(json.dumps({"success": result}))
json_console.print(
json.dumps({"success": result, "extrinsic_identifier": ext_id or None})
)
return result

def stake_get_children(
Expand Down Expand Up @@ -4990,7 +4996,7 @@ def stake_childkey_take(
f"wait_for_inclusion: {wait_for_inclusion}\n"
f"wait_for_finalization: {wait_for_finalization}\n"
)
results: list[tuple[Optional[int], bool]] = self._run_command(
results: list[tuple[Optional[int], bool, Optional[str]]] = self._run_command(
children_hotkeys.childkey_take(
wallet=wallet,
subtensor=self.initialize_chain(network),
Expand All @@ -5004,8 +5010,8 @@ def stake_childkey_take(
)
if json_output:
output = {}
for netuid_, success in results:
output[netuid_] = success
for netuid_, success, ext_id in results:
output[netuid_] = {"success": success, "extrinsic_identifier": ext_id}
json_console.print(json.dumps(output))
return results

Expand Down Expand Up @@ -5128,7 +5134,7 @@ def sudo_set(
f"param_name: {param_name}\n"
f"param_value: {param_value}"
)
result, err_msg = self._run_command(
result, err_msg, ext_id = self._run_command(
sudo.sudo_set_hyperparameter(
wallet,
self.initialize_chain(network),
Expand All @@ -5140,7 +5146,15 @@ def sudo_set(
)
)
if json_output:
json_console.print(json.dumps({"success": result, "err_msg": err_msg}))
json_console.print(
json.dumps(
{
"success": result,
"err_msg": err_msg,
"extrinsic_identifier": ext_id,
}
)
)
return result

def sudo_get(
Expand Down Expand Up @@ -5225,7 +5239,7 @@ def sudo_senate_vote(
None,
"--vote-aye/--vote-nay",
prompt="Enter y to vote Aye, or enter n to vote Nay",
help="The vote casted on the proposal",
help="The vote cast on the proposal",
),
):
"""
Expand Down Expand Up @@ -5302,11 +5316,13 @@ def sudo_set_take(
)
raise typer.Exit()
logger.debug(f"args:\nnetwork: {network}\ntake: {take}")
result = self._run_command(
result, ext_id = self._run_command(
sudo.set_take(wallet, self.initialize_chain(network), take)
)
if json_output:
json_console.print(json.dumps({"success": result}))
json_console.print(
json.dumps({"success": result, "extrinsic_identifier": ext_id})
)
return result

def sudo_get_take(
Expand Down Expand Up @@ -5870,13 +5886,15 @@ def subnets_set_identity(
logger.debug(
f"args:\nnetwork: {network}\nnetuid: {netuid}\nidentity: {identity}"
)
success = self._run_command(
success, ext_id = self._run_command(
subnets.set_identity(
wallet, self.initialize_chain(network), netuid, identity, prompt
)
)
if json_output:
json_console.print(json.dumps({"success": success}))
json_console.print(
json.dumps({"success": success, "extrinsic_identifier": ext_id})
)

def subnets_pow_register(
self,
Expand Down Expand Up @@ -6204,6 +6222,7 @@ def weights_reveal(
[green]$[/green] btcli wt reveal --netuid 1 --uids 1,2,3,4 --weights 0.1,0.2,0.3,0.4 --salt 163,241,217,11,161,142,147,189
"""
self.verbosity_handler(quiet, verbose, json_output)
# TODO think we need to ','.split uids and weights ?
uids = list_prompt(uids, int, "UIDs of interest for the specified netuid")
weights = list_prompt(
weights, float, "Corresponding weights for the specified UIDs"
Expand Down
40 changes: 23 additions & 17 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Optional
import subprocess

from async_substrate_interface import AsyncExtrinsicReceipt
from bittensor_wallet import Wallet
from Crypto.Hash import keccak
import numpy as np
Expand All @@ -40,6 +41,7 @@
unlock_key,
hex_to_bytes,
get_hotkey_pub_ss58,
print_extrinsic_id,
)

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -679,7 +681,7 @@ async def burned_register_extrinsic(
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
era: Optional[int] = None,
) -> tuple[bool, str]:
) -> tuple[bool, str, Optional[str]]:
"""Registers the wallet to chain by recycling TAO.

:param subtensor: The SubtensorInterface object to use for the call, initialized
Expand All @@ -698,7 +700,7 @@ async def burned_register_extrinsic(
"""

if not (unlock_status := unlock_key(wallet, print_out=False)).success:
return False, unlock_status.message
return False, unlock_status.message, None

with console.status(
f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]...",
Expand Down Expand Up @@ -742,7 +744,7 @@ async def burned_register_extrinsic(
f"hotkey: [{COLOR_PALETTE.G.HK}]{neuron.hotkey}[/{COLOR_PALETTE.G.HK}]\n"
f"coldkey: [{COLOR_PALETTE.G.CK}]{neuron.coldkey}[/{COLOR_PALETTE.G.CK}]"
)
return True, "Already registered"
return True, "Already registered", None

with console.status(
":satellite: Recycling TAO for Registration...", spinner="aesthetic"
Expand All @@ -755,16 +757,18 @@ async def burned_register_extrinsic(
"hotkey": get_hotkey_pub_ss58(wallet),
},
)
success, err_msg = await subtensor.sign_and_send_extrinsic(
success, err_msg, ext_receipt = await subtensor.sign_and_send_extrinsic(
call, wallet, wait_for_inclusion, wait_for_finalization, era=era_
)

if not success:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
await asyncio.sleep(0.5)
return False, err_msg
return False, err_msg, None
# Successful registration, final check for neuron and pubkey
else:
ext_id = await ext_receipt.get_extrinsic_identifier()
await print_extrinsic_id(ext_receipt)
with console.status(":satellite: Checking Balance...", spinner="aesthetic"):
block_hash = await subtensor.substrate.get_chain_head()
new_balance, netuids_for_hotkey, my_uid = await asyncio.gather(
Expand All @@ -791,13 +795,13 @@ async def burned_register_extrinsic(
console.print(
f":white_heavy_check_mark: [green]Registered on netuid {netuid} with UID {my_uid}[/green]"
)
return True, f"Registered on {netuid} with UID {my_uid}"
return True, f"Registered on {netuid} with UID {my_uid}", ext_id
else:
# neuron not found, try again
err_console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
return False, "Unknown error. Neuron not found."
return False, "Unknown error. Neuron not found.", ext_id


async def run_faucet_extrinsic(
Expand Down Expand Up @@ -1749,7 +1753,7 @@ async def swap_hotkey_extrinsic(
new_wallet: Wallet,
netuid: Optional[int] = None,
prompt: bool = False,
) -> bool:
) -> tuple[bool, Optional[AsyncExtrinsicReceipt]]:
"""
Performs an extrinsic update for swapping two hotkeys on the chain

Expand All @@ -1770,32 +1774,32 @@ async def swap_hotkey_extrinsic(
err_console.print(
f":cross_mark: [red]Failed[/red]: Original hotkey {hk_ss58} is not registered on subnet {netuid}"
)
return False
return False, None

elif not len(netuids_registered) > 0:
err_console.print(
f"Original hotkey [dark_orange]{hk_ss58}[/dark_orange] is not registered on any subnet. "
f"Please register and try again"
)
return False
return False, None

if netuid is not None:
if netuid in netuids_registered_new_hotkey:
err_console.print(
f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} "
f"is already registered on subnet {netuid}"
)
return False
return False, None
else:
if len(netuids_registered_new_hotkey) > 0:
err_console.print(
f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} "
f"is already registered on subnet(s) {netuids_registered_new_hotkey}"
)
return False
return False, None

if not unlock_key(wallet).success:
return False
return False, None

if prompt:
# Prompt user for confirmation.
Expand All @@ -1815,7 +1819,7 @@ async def swap_hotkey_extrinsic(
)

if not Confirm.ask(confirm_message):
return False
return False, None
print_verbose(
f"Swapping {wallet.name}'s hotkey ({hk_ss58} - {wallet.hotkey_str}) with "
f"{new_wallet.name}'s hotkey ({new_hk_ss58} - {new_wallet.hotkey_str})"
Expand All @@ -1832,15 +1836,17 @@ async def swap_hotkey_extrinsic(
call_function="swap_hotkey",
call_params=call_params,
)
success, err_msg = await subtensor.sign_and_send_extrinsic(call, wallet)
success, err_msg, ext_receipt = await subtensor.sign_and_send_extrinsic(
call, wallet
)

if success:
console.print(
f"Hotkey {hk_ss58} ({wallet.hotkey_str}) swapped for new hotkey: "
f"{new_hk_ss58} ({new_wallet.hotkey_str})"
)
return True
return True, ext_receipt
else:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
time.sleep(0.5)
return False
return False, ext_receipt
19 changes: 11 additions & 8 deletions bittensor_cli/src/bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import asyncio
import hashlib
import time
from typing import Union, List, TYPE_CHECKING
from typing import Union, List, TYPE_CHECKING, Optional

from bittensor_wallet import Wallet, Keypair
import numpy as np
Expand All @@ -38,6 +38,7 @@
format_error_message,
unlock_key,
get_hotkey_pub_ss58,
print_extrinsic_id,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -291,7 +292,7 @@ async def root_register_extrinsic(
wallet: Wallet,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
) -> tuple[bool, str]:
) -> tuple[bool, str, Optional[str]]:
r"""Registers the wallet to root network.

:param subtensor: The SubtensorInterface object
Expand All @@ -307,7 +308,7 @@ async def root_register_extrinsic(
"""

if not (unlock := unlock_key(wallet)).success:
return False, unlock.message
return False, unlock.message, None

print_verbose(f"Checking if hotkey ({wallet.hotkey_str}) is registered on root")
is_registered = await is_hotkey_registered(
Expand All @@ -317,15 +318,15 @@ async def root_register_extrinsic(
console.print(
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
)
return True, "Already registered on root network"
return True, "Already registered on root network", None

with console.status(":satellite: Registering to root network...", spinner="earth"):
call = await subtensor.substrate.compose_call(
call_module="SubtensorModule",
call_function="root_register",
call_params={"hotkey": get_hotkey_pub_ss58(wallet)},
)
success, err_msg = await subtensor.sign_and_send_extrinsic(
success, err_msg, ext_receipt = await subtensor.sign_and_send_extrinsic(
call,
wallet=wallet,
wait_for_inclusion=wait_for_inclusion,
Expand All @@ -335,10 +336,12 @@ async def root_register_extrinsic(
if not success:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
await asyncio.sleep(0.5)
return False, err_msg
return False, err_msg, None

# Successful registration, final check for neuron and pubkey
else:
ext_id = await ext_receipt.get_extrinsic_identifier()
await print_extrinsic_id(ext_receipt)
uid = await subtensor.query(
module="SubtensorModule",
storage_function="Uids",
Expand All @@ -348,13 +351,13 @@ async def root_register_extrinsic(
console.print(
f":white_heavy_check_mark: [green]Registered with UID {uid}[/green]"
)
return True, f"Registered with UID {uid}"
return True, f"Registered with UID {uid}", ext_id
else:
# neuron not found, try again
err_console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
return False, "Unknown error. Neuron not found."
return False, "Unknown error. Neuron not found.", ext_id


async def set_root_weights_extrinsic(
Expand Down
Loading
Loading