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

[fix] rename ss58_hotkey to hotkey_ss58 #1074

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions bittensor/_cli/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run (cli):
if cli.config.netuid != None:
# If a netuid is provided, inspect the hotkey and the neuron
dendrite = bittensor.dendrite( wallet = wallet )
neuron = subtensor.get_neuron_for_pubkey_and_subnet( ss58_hotkey = wallet.hotkey.ss58_address, netuid = cli.config.netuid )
neuron = subtensor.get_neuron_for_pubkey_and_subnet( hotkey_ss58 = wallet.hotkey.ss58_address, netuid = cli.config.netuid )
if neuron.is_null:
registered = '[bold white]No[/bold white]'
stake = bittensor.Balance.from_tao( 0 )
Expand Down Expand Up @@ -99,12 +99,12 @@ def run (cli):
stake = bittensor.Balance.from_tao( 0 )
else:
# Registered on subnets
subnets_registered = subtensor.get_netuids_for_hotkey( ss58_hotkey = wallet.hotkey.ss58_address )
subnets_registered = subtensor.get_netuids_for_hotkey( hotkey_ss58 = wallet.hotkey.ss58_address )
subnets = f'[bold white]{subnets_registered}[/bold white]'

emission = bittensor.Balance.from_rao( 0 )
for netuid in subnets_registered:
neuron = subtensor.neuron_for_pubkey( ss58_hotkey = wallet.hotkey.ss58_address, netuid = netuid )
neuron = subtensor.neuron_for_pubkey( hotkey_ss58 = wallet.hotkey.ss58_address, netuid = netuid )
emission += bittensor.Balance.from_rao( neuron.emission * 1000000000 )

cold_balance = wallet.get_balance( subtensor = subtensor )
Expand Down
6 changes: 3 additions & 3 deletions bittensor/_cli/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def run( cli ):
final_amounts: List[Union[float, Balance]] = []
for hotkey in tqdm(hotkeys_to_stake_to):
hotkey: Tuple[Optional[str], str] # (hotkey_name (or None), hotkey_ss58)
if not subtensor.is_hotkey_registered_any( hotkey_ss58 = hotkey ):
if not subtensor.is_hotkey_registered_any( hotkey_ss58 = hotkey[1] ):
# Hotkey is not registered.
if (len(hotkeys_to_stake_to) == 1):
# Only one hotkey, error
bittensor.__console__.print(f"[red]Hotkey [bold]{hotkey}[/bold] is not registered. Aborting.[/red]")
bittensor.__console__.print(f"[red]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Aborting.[/red]")
return None
else:
# Otherwise, print warning and skip
bittensor.__console__.print(f"[yellow]Hotkey [bold]{hotkey}[/bold] is not registered. Skipping.[/yellow]")
bittensor.__console__.print(f"[yellow]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Skipping.[/yellow]")
continue


Expand Down
6 changes: 3 additions & 3 deletions bittensor/_cli/commands/unstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ def run( cli ):
final_amounts: List[Union[float, Balance]] = []
for hotkey in tqdm(hotkeys_to_unstake_from):
hotkey: Tuple[Optional[str], str] # (hotkey_name (or None), hotkey_ss58)
if not subtensor.is_hotkey_registered_any( hotkey_ss58 = hotkey ):
if not subtensor.is_hotkey_registered_any( hotkey_ss58 = hotkey[1] ):
# Hotkey is not registered.
if (len(hotkeys_to_unstake_from) == 1):
# Only one hotkey, error
bittensor.__console__.print(f"[red]Hotkey [bold]{hotkey}[/bold] is not registered. Aborting.[/red]")
bittensor.__console__.print(f"[red]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Aborting.[/red]")
return None
else:
# Otherwise, print warning and skip
bittensor.__console__.print(f"[yellow]Hotkey [bold]{hotkey}[/bold] is not registered. Skipping.[/yellow]")
bittensor.__console__.print(f"[yellow]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Skipping.[/yellow]")
continue

unstake_amount_tao: float = cli.config.get('amount') # The amount specified to unstake.
Expand Down
34 changes: 17 additions & 17 deletions bittensor/_subtensor/subtensor_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,35 +653,35 @@ def make_substrate_call_with_retry():
#### Neuron information per subnet ####
########################################

def is_hotkey_registered_any( self, ss58_hotkey: str, block: Optional[int] = None) -> bool:
return len( self.get_netuids_for_hotkey( ss58_hotkey, block) ) > 0
def is_hotkey_registered_any( self, hotkey_ss58: str, block: Optional[int] = None) -> bool:
return len( self.get_netuids_for_hotkey( hotkey_ss58, block) ) > 0

def is_hotkey_registered_on_subnet( self, ss58_hotkey: str, netuid: int, block: Optional[int] = None) -> bool:
return self.get_uid_for_hotkey_on_subnet( ss58_hotkey, netuid, block ) != None
def is_hotkey_registered_on_subnet( self, hotkey_ss58: str, netuid: int, block: Optional[int] = None) -> bool:
return self.get_uid_for_hotkey_on_subnet( hotkey_ss58, netuid, block ) != None

def is_hotkey_registered( self, ss58_hotkey: str, netuid: int, block: Optional[int] = None) -> bool:
return self.get_uid_for_hotkey_on_subnet( ss58_hotkey, netuid, block ) != None
def is_hotkey_registered( self, hotkey_ss58: str, netuid: int, block: Optional[int] = None) -> bool:
return self.get_uid_for_hotkey_on_subnet( hotkey_ss58, netuid, block ) != None

def get_uid_for_hotkey_on_subnet( self, ss58_hotkey: str, netuid: int, block: Optional[int] = None) -> int:
return self.query_paratensor( 'Uids', block, [ netuid, ss58_hotkey ] ).value
def get_uid_for_hotkey_on_subnet( self, hotkey_ss58: str, netuid: int, block: Optional[int] = None) -> int:
return self.query_paratensor( 'Uids', block, [ netuid, hotkey_ss58 ] ).value

def get_all_uids_for_hotkey( self, ss58_hotkey: str, block: Optional[int] = None) -> List[int]:
return [ self.get_uid_for_hotkey_on_subnet( ss58_hotkey, netuid, block) for netuid in self.get_netuids_for_hotkey( ss58_hotkey, block)]
def get_all_uids_for_hotkey( self, hotkey_ss58: str, block: Optional[int] = None) -> List[int]:
return [ self.get_uid_for_hotkey_on_subnet( hotkey_ss58, netuid, block) for netuid in self.get_netuids_for_hotkey( hotkey_ss58, block)]

def get_netuids_for_hotkey( self, ss58_hotkey: str, block: Optional[int] = None) -> List[int]:
result = self.query_map_paratensor( 'IsNetworkMember', block, [ ss58_hotkey ] )
def get_netuids_for_hotkey( self, hotkey_ss58: str, block: Optional[int] = None) -> List[int]:
result = self.query_map_paratensor( 'IsNetworkMember', block, [ hotkey_ss58 ] )
netuids = []
for netuid, is_member in result.records:
if is_member:
netuids.append( netuid.value )
return netuids

def get_neuron_for_pubkey_and_subnet( self, ss58_hotkey: str, netuid: int, block: Optional[int] = None ) -> List[NeuronInfo]:
return self.neuron_for_uid( self.get_uid_for_hotkey_on_subnet(ss58_hotkey, netuid, block=block), netuid, block = block)
def get_neuron_for_pubkey_and_subnet( self, hotkey_ss58: str, netuid: int, block: Optional[int] = None ) -> List[NeuronInfo]:
return self.neuron_for_uid( self.get_uid_for_hotkey_on_subnet(hotkey_ss58, netuid, block=block), netuid, block = block)

def get_all_neurons_for_pubkey( self, ss58_hotkey: str, block: Optional[int] = None ) -> List[NeuronInfo]:
netuids = self.get_netuids_for_hotkey( ss58_hotkey, block)
uids = [self.get_uid_for_hotkey_on_subnet(ss58_hotkey, net) for net in netuids]
def get_all_neurons_for_pubkey( self, hotkey_ss58: str, block: Optional[int] = None ) -> List[NeuronInfo]:
netuids = self.get_netuids_for_hotkey( hotkey_ss58, block)
uids = [self.get_uid_for_hotkey_on_subnet(hotkey_ss58, net) for net in netuids]
return [self.neuron_for_uid( uid, net ) for uid, net in list(zip(uids, netuids))]

def neuron_has_validator_permit( self, uid: int, netuid: int, block: Optional[int] = None ) -> Optional[bool]:
Expand Down