Skip to content

Commit

Permalink
[fix] rename ss58_hotkey to hotkey_ss58 (#1074)
Browse files Browse the repository at this point in the history
* rename ss58_hotkey to hotkey_ss58

* fix call

* change message output
  • Loading branch information
camfairchild authored Jan 26, 2023
1 parent c0b6106 commit 8d3d574
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
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
8 changes: 4 additions & 4 deletions bittensor/_cli/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,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 Expand Up @@ -123,7 +123,7 @@ def run( cli ):
if not config.no_prompt:
if not Confirm.ask(f"Do you want to stake to the following keys from {wallet.name}:\n" + \
"".join([
f" [bold white]- {hotkey[0] + ':' if hotkey[0] else ''}{hotkey[1]}: {amount}𝜏[/bold white]\n" for hotkey, amount in zip(final_hotkeys, final_amounts)
f" [bold white]- {hotkey[0] + ':' if hotkey[0] else ''}{hotkey[1]}: {f'${amount} \u03C4' if amount else 'All'}[/bold white]\n" for hotkey, amount in zip(final_hotkeys, final_amounts)
])
):
return None
Expand Down
8 changes: 4 additions & 4 deletions bittensor/_cli/commands/unstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,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 Expand Up @@ -215,7 +215,7 @@ def run( cli ):
if not cli.config.no_prompt:
if not Confirm.ask(f"Do you want to unstake from the following keys to {wallet.name}:\n" + \
"".join([
f" [bold white]- {hotkey[0] + ':' if hotkey[0] else ''}{hotkey[1]}: {amount}𝜏[/bold white]\n" for hotkey, amount in zip(final_hotkeys, final_amounts)
f" [bold white]- {hotkey[0] + ':' if hotkey[0] else ''}{hotkey[1]}: {f'${amount} \u03C4' if amount else 'All'}[/bold white]\n" for hotkey, amount in zip(final_hotkeys, final_amounts)
])
):
return None
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

0 comments on commit 8d3d574

Please sign in to comment.