diff --git a/bittensor_cli/src/__init__.py b/bittensor_cli/src/__init__.py index fc1931fd6..95a4d3c39 100644 --- a/bittensor_cli/src/__init__.py +++ b/bittensor_cli/src/__init__.py @@ -1,6 +1,4 @@ from enum import Enum -from dataclasses import dataclass -from typing import Any, Optional class Constants: @@ -37,47 +35,6 @@ class Constants: delegates_detail_url = "https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json" -@dataclass -class DelegatesDetails: - display: str - additional: list[tuple[str, str]] - web: str - legal: Optional[str] = None - riot: Optional[str] = None - email: Optional[str] = None - pgp_fingerprint: Optional[str] = None - image: Optional[str] = None - twitter: Optional[str] = None - - @classmethod - def from_chain_data(cls, data: dict[str, Any]) -> "DelegatesDetails": - def decode(key: str, default=""): - try: - if isinstance(data.get(key), dict): - value = next(data.get(key).values()) - return bytes(value[0]).decode("utf-8") - elif isinstance(data.get(key), int): - return data.get(key) - elif isinstance(data.get(key), tuple): - return bytes(data.get(key)[0]).decode("utf-8") - else: - return default - except (UnicodeDecodeError, TypeError): - return default - - return cls( - display=decode("display"), - additional=decode("additional", []), - web=decode("web"), - legal=decode("legal"), - riot=decode("riot"), - email=decode("email"), - pgp_fingerprint=decode("pgp_fingerprint", None), - image=decode("image"), - twitter=decode("twitter"), - ) - - class Defaults: netuid = 1 rate_tolerance = 0.005 diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index e0aedecfa..6cb3f592a 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -32,7 +32,6 @@ CrowdloanData, ColdkeySwapAnnouncementInfo, ) -from bittensor_cli.src import DelegatesDetails from bittensor_cli.src.bittensor.balances import Balance, fixed_to_float from bittensor_cli.src import Constants, defaults, TYPE_REGISTRY from bittensor_cli.src.bittensor.extrinsics.mev_shield import encrypt_extrinsic @@ -40,7 +39,6 @@ format_error_message, console, print_error, - decode_hex_identity_dict, validate_chain_endpoint, u16_normalized_float, MEV_SHIELD_PUBLIC_KEY_SIZE, @@ -1518,39 +1516,6 @@ async def get_vote_data( else: return ProposalVoteData(vote_data) - async def get_delegate_identities( - self, block_hash: Optional[str] = None - ) -> dict[str, DelegatesDetails]: - """ - Fetches delegates identities from the chain and GitHub. Preference is given to chain data, and missing info - is filled-in by the info from GitHub. At some point, we want to totally move away from fetching this info - from GitHub, but chain data is still limited in that regard. - - :param block_hash: the hash of the blockchain block for the query - - :return: {ss58: DelegatesDetails, ...} - - """ - identities_info = await self.substrate.query_map( - module="Registry", - storage_function="IdentityOf", - block_hash=block_hash, - ) - - all_delegates_details = {} - async for ss58_address, identity in identities_info: - all_delegates_details.update( - { - decode_account_id( - ss58_address[0] - ): DelegatesDetails.from_chain_data( - decode_hex_identity_dict(identity.value["info"]) - ) - } - ) - - return all_delegates_details - async def get_mechagraph_info( self, netuid: int, mech_id: int, block_hash: Optional[str] = None ) -> Optional[MetagraphInfo]: diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 9851a9016..fe6c7c6b9 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -147,6 +147,24 @@ def create_table(*columns, title: str = "", **overrides) -> Table: return Table(*columns, **config) +def get_hotkey_identity_name( + identities: dict[str, Any], hotkey_ss58: str +) -> Optional[str]: + """Return a hotkey display name from the V2 identity map, if present.""" + hotkey_identity = identities.get("hotkeys", {}).get(hotkey_ss58, {}) + identity_data = hotkey_identity.get("identity", {}) + return identity_data.get("name") or identity_data.get("display") or None + + +def get_coldkey_identity_name( + identities: dict[str, Any], coldkey_ss58: str +) -> Optional[str]: + """Return a coldkey display name from the V2 identity map, if present.""" + coldkey_identity = identities.get("coldkeys", {}).get(coldkey_ss58, {}) + identity_data = coldkey_identity.get("identity", {}) + return identity_data.get("name") or identity_data.get("display") or None + + jinja_env = Environment( loader=PackageLoader("bittensor_cli", "src/bittensor/templates"), autoescape=select_autoescape(), diff --git a/bittensor_cli/src/commands/stake/auto_staking.py b/bittensor_cli/src/commands/stake/auto_staking.py index 0afee7bce..39896294f 100644 --- a/bittensor_cli/src/commands/stake/auto_staking.py +++ b/bittensor_cli/src/commands/stake/auto_staking.py @@ -17,6 +17,8 @@ print_error, unlock_key, print_extrinsic_id, + get_hotkey_identity_name, + get_coldkey_identity_name, ) if TYPE_CHECKING: @@ -45,7 +47,6 @@ async def show_auto_stake_destinations( subnet_info, auto_destinations, identities, - delegate_identities, ) = await asyncio.gather( subtensor.all_subnets(block_hash=chain_head), subtensor.get_auto_stake_destinations( @@ -54,36 +55,21 @@ async def show_auto_stake_destinations( reuse_block=True, ), subtensor.fetch_coldkey_hotkey_identities(block_hash=chain_head), - subtensor.get_delegate_identities(block_hash=chain_head), ) subnet_map = {info.netuid: info for info in subnet_info} auto_destinations = auto_destinations or {} identities = identities or {} - delegate_identities = delegate_identities or {} - hotkey_identities = identities.get("hotkeys", {}) def resolve_identity(hotkey: str) -> Optional[str]: if not hotkey: return None - identity_entry = hotkey_identities.get(hotkey, {}).get("identity") - if identity_entry: - display_name = identity_entry.get("name") or identity_entry.get("display") - if display_name: - return display_name - - delegate_info = delegate_identities.get(hotkey) - if delegate_info and getattr(delegate_info, "display", ""): - return delegate_info.display - - return None + return get_hotkey_identity_name(identities, hotkey) coldkey_display = wallet_name if not coldkey_display: - coldkey_identity = identities.get("coldkeys", {}).get(coldkey_ss58, {}) - if identity_data := coldkey_identity.get("identity"): - coldkey_display = identity_data.get("name") or identity_data.get("display") + coldkey_display = get_coldkey_identity_name(identities, coldkey_ss58) if not coldkey_display: coldkey_display = f"{coldkey_ss58[:6]}...{coldkey_ss58[-6:]}" @@ -183,10 +169,9 @@ async def set_auto_stake_destination( try: chain_head = await subtensor.substrate.get_chain_head() - subnet_info, identities, delegate_identities = await asyncio.gather( + subnet_info, identities = await asyncio.gather( subtensor.subnet(netuid, block_hash=chain_head), subtensor.fetch_coldkey_hotkey_identities(block_hash=chain_head), - subtensor.get_delegate_identities(block_hash=chain_head), ) except ValueError: print_error(f"Subnet with netuid {netuid} does not exist") @@ -194,17 +179,8 @@ async def set_auto_stake_destination( hotkey_identity = "" identities = identities or {} - delegate_identities = delegate_identities or {} - hotkey_identity_entry = identities.get("hotkeys", {}).get(hotkey_ss58, {}) - if identity_data := hotkey_identity_entry.get("identity"): - hotkey_identity = ( - identity_data.get("name") or identity_data.get("display") or "" - ) - if not hotkey_identity: - delegate_info = delegate_identities.get(hotkey_ss58) - if delegate_info and getattr(delegate_info, "display", ""): - hotkey_identity = delegate_info.display + hotkey_identity = get_hotkey_identity_name(identities, hotkey_ss58) or "" if prompt_user and not json_output: table = create_table( diff --git a/bittensor_cli/src/commands/stake/list.py b/bittensor_cli/src/commands/stake/list.py index 24e5dbaa7..61fc611e2 100644 --- a/bittensor_cli/src/commands/stake/list.py +++ b/bittensor_cli/src/commands/stake/list.py @@ -20,6 +20,7 @@ millify_tao, get_subnet_name, json_console, + get_hotkey_identity_name, ) if TYPE_CHECKING: @@ -40,16 +41,17 @@ async def stake_list( async def get_stake_data(block_hash_: str = None): ( sub_stakes_, - registered_delegate_info_, + hotkey_identity_map_, _dynamic_info, ) = await asyncio.gather( subtensor.get_stake_for_coldkey( coldkey_ss58=coldkey_address, block_hash=block_hash_ ), - subtensor.get_delegate_identities(block_hash=block_hash_), + subtensor.fetch_coldkey_hotkey_identities(block_hash=block_hash_), subtensor.all_subnets(block_hash=block_hash_), ) + hotkey_identity_map_ = hotkey_identity_map_ or {"hotkeys": {}, "coldkeys": {}} claimable_amounts_ = {} if sub_stakes_: claimable_amounts_ = await subtensor.get_claimable_stakes_for_coldkey( @@ -61,11 +63,15 @@ async def get_stake_data(block_hash_: str = None): dynamic_info__ = {info.netuid: info for info in _dynamic_info} return ( sub_stakes_, - registered_delegate_info_, + hotkey_identity_map_, dynamic_info__, claimable_amounts_, ) + def format_hotkey_name(hotkey_ss58_: str, hotkey_identity_map_: dict) -> str: + display_name = get_hotkey_identity_name(hotkey_identity_map_, hotkey_ss58_) + return f"{display_name} ({hotkey_ss58_})" if display_name else hotkey_ss58_ + def define_table( hotkey_name_: str, rows: list[list[str]], @@ -156,11 +162,7 @@ def create_table( substakes_: list[StakeInfo], claimable_amounts_: dict[str, dict[int, Balance]], ): - name_ = ( - f"{registered_delegate_info[hotkey_].display} ({hotkey_})" - if hotkey_ in registered_delegate_info - else hotkey_ - ) + name_ = format_hotkey_name(hotkey_, hotkey_identity_map) rows = [] total_tao_value_ = Balance(0) total_swapped_tao_value_ = Balance(0) @@ -481,7 +483,7 @@ def format_cell( ( ( sub_stakes, - registered_delegate_info, + hotkey_identity_map, dynamic_info, claimable_amounts, ), @@ -509,11 +511,7 @@ def format_cell( "\n[bold]Multiple hotkeys found. Please select one for live monitoring:[/bold]" ) for idx, hotkey in enumerate(hotkeys_to_substakes.keys()): - name = ( - f"{registered_delegate_info[hotkey].display} ({hotkey})" - if hotkey in registered_delegate_info - else hotkey - ) + name = format_hotkey_name(hotkey, hotkey_identity_map) console.print(f"[{idx}] [{COLOR_PALETTE['GENERAL']['HEADER']}]{name}") selected_idx = Prompt.ask( @@ -524,11 +522,7 @@ def format_cell( else: selected_hotkey = list(hotkeys_to_substakes.keys())[0] - hotkey_name = ( - f"{registered_delegate_info[selected_hotkey].display} ({selected_hotkey})" - if selected_hotkey in registered_delegate_info - else selected_hotkey - ) + hotkey_name = format_hotkey_name(selected_hotkey, hotkey_identity_map) refresh_interval = 10 # seconds progress = Progress( @@ -549,7 +543,7 @@ def format_cell( block_hash = await subtensor.substrate.get_chain_head() ( sub_stakes, - registered_delegate_info, + _hotkey_identity_map, dynamic_info_, claimable_amounts_live, ) = await get_stake_data(block_hash) diff --git a/bittensor_cli/src/commands/stake/move.py b/bittensor_cli/src/commands/stake/move.py index b7b28c213..f9b3693ca 100644 --- a/bittensor_cli/src/commands/stake/move.py +++ b/bittensor_cli/src/commands/stake/move.py @@ -22,6 +22,7 @@ unlock_key, get_hotkey_pub_ss58, print_extrinsic_id, + get_hotkey_identity_name, ) if TYPE_CHECKING: @@ -324,10 +325,9 @@ async def stake_move_transfer_selection( wallet: Wallet, ): """Selection interface for moving stakes between hotkeys and subnets.""" - stakes, ck_hk_identities, old_identities = await asyncio.gather( + stakes, ck_hk_identities = await asyncio.gather( subtensor.get_stake_for_coldkey(coldkey_ss58=wallet.coldkeypub.ss58_address), subtensor.fetch_coldkey_hotkey_identities(), - subtensor.get_delegate_identities(), ) hotkey_stakes = {} @@ -353,14 +353,7 @@ async def stake_move_transfer_selection( hotkeys_info = [] for idx, (hotkey_ss58, netuid_stakes) in enumerate(hotkey_stakes.items()): - if hk_identity := ck_hk_identities["hotkeys"].get(hotkey_ss58): - hotkey_name = hk_identity.get("identity", {}).get( - "name", "" - ) or hk_identity.get("display", "~") - elif old_identity := old_identities.get(hotkey_ss58): - hotkey_name = old_identity.display - else: - hotkey_name = "~" + hotkey_name = get_hotkey_identity_name(ck_hk_identities, hotkey_ss58) or "~" hotkeys_info.append( { "index": idx, diff --git a/bittensor_cli/src/commands/stake/remove.py b/bittensor_cli/src/commands/stake/remove.py index b99458641..129bf7363 100644 --- a/bittensor_cli/src/commands/stake/remove.py +++ b/bittensor_cli/src/commands/stake/remove.py @@ -29,6 +29,7 @@ json_console, get_hotkey_pub_ss58, print_extrinsic_id, + get_hotkey_identity_name, ) if TYPE_CHECKING: @@ -67,12 +68,10 @@ async def unstake( ( all_sn_dynamic_info_, ck_hk_identities, - old_identities, stake_infos, ) = await asyncio.gather( subtensor.all_subnets(block_hash=chain_head), subtensor.fetch_coldkey_hotkey_identities(block_hash=chain_head), - subtensor.get_delegate_identities(block_hash=chain_head), subtensor.get_stake_for_coldkey(coldkey_ss58, block_hash=chain_head), ) all_sn_dynamic_info = {info.netuid: info for info in all_sn_dynamic_info_} @@ -82,7 +81,6 @@ async def unstake( hotkeys_to_unstake_from, unstake_all_from_hk = await _unstake_selection( all_sn_dynamic_info, ck_hk_identities, - old_identities, stake_infos, netuid=netuid, ) @@ -125,7 +123,6 @@ async def unstake( exclude_hotkeys=exclude_hotkeys, stake_infos=stake_infos, identities=ck_hk_identities, - old_identities=old_identities, ) with console.status( @@ -522,13 +519,11 @@ async def unstake_all( ( stake_info, ck_hk_identities, - old_identities, all_sn_dynamic_info_, current_wallet_balance, ) = await asyncio.gather( subtensor.get_stake_for_coldkey(coldkey_ss58), subtensor.fetch_coldkey_hotkey_identities(), - subtensor.get_delegate_identities(), subtensor.all_subnets(), subtensor.get_balance(coldkey_ss58), ) @@ -542,7 +537,6 @@ async def unstake_all( exclude_hotkeys=exclude_hotkeys, stake_infos=stake_info, identities=ck_hk_identities, - old_identities=old_identities, ) elif not hotkey_ss58_address: hotkeys = [(wallet.hotkey_str, get_hotkey_pub_ss58(wallet), None)] @@ -1196,7 +1190,6 @@ async def _get_extrinsic_fee( async def _unstake_selection( dynamic_info, identities, - old_identities, stake_infos, netuid: Optional[int] = None, ) -> tuple[list[tuple[str, str, int]], bool]: @@ -1226,7 +1219,6 @@ async def _unstake_selection( hotkey_name = get_hotkey_identity( hotkey_ss58=hotkey_ss58, identities=identities, - old_identities=old_identities, ) hotkeys_info.append( { @@ -1418,7 +1410,6 @@ def _get_hotkeys_to_unstake( exclude_hotkeys: list[str], stake_infos: list, identities: dict, - old_identities: dict, ) -> list[tuple[Optional[str], str, None]]: """Get list of hotkeys to unstake from based on input parameters. @@ -1449,7 +1440,7 @@ def _get_hotkeys_to_unstake( wallet_hotkey_addresses = {hk[1] for hk in wallet_hotkeys} chain_hotkeys = [ ( - get_hotkey_identity(stake_info.hotkey_ss58, identities, old_identities), + get_hotkey_identity(stake_info.hotkey_ss58, identities), stake_info.hotkey_ss58, None, ) @@ -1603,23 +1594,16 @@ def _print_table_and_slippage( def get_hotkey_identity( hotkey_ss58: str, identities: dict, - old_identities: dict, ) -> str: - """Get identity name for a hotkey from identities or old_identities. + """Get identity name for a hotkey from the V2-backed identity map. Args: hotkey_ss58 (str): The hotkey SS58 address identities (dict): Current identities from fetch_coldkey_hotkey_identities - old_identities (dict): Old identities from get_delegate_identities Returns: str: Identity name or truncated address """ - if hk_identity := identities["hotkeys"].get(hotkey_ss58): - return hk_identity.get("identity", {}).get("name", "") or hk_identity.get( - "display", "~" - ) - elif old_identity := old_identities.get(hotkey_ss58): - return old_identity.display - else: - return f"{hotkey_ss58[:4]}...{hotkey_ss58[-4:]}" + return get_hotkey_identity_name(identities, hotkey_ss58) or ( + f"{hotkey_ss58[:4]}...{hotkey_ss58[-4:]}" + ) diff --git a/bittensor_cli/src/commands/stake/wizard.py b/bittensor_cli/src/commands/stake/wizard.py index 1b11f93c3..8875ee8f5 100644 --- a/bittensor_cli/src/commands/stake/wizard.py +++ b/bittensor_cli/src/commands/stake/wizard.py @@ -21,6 +21,7 @@ get_hotkey_pub_ss58, group_subnets, get_hotkey_wallets_for_wallet, + get_hotkey_identity_name, ) from bittensor_cli.src.commands.stake.move import ( stake_move_transfer_selection, @@ -102,12 +103,11 @@ async def stake_movement_wizard( # Get stakes for the wallet with console.status("Retrieving stake information..."): - stakes, ck_hk_identities, old_identities = await asyncio.gather( + stakes, ck_hk_identities = await asyncio.gather( subtensor.get_stake_for_coldkey( coldkey_ss58=wallet.coldkeypub.ss58_address ), subtensor.fetch_coldkey_hotkey_identities(), - subtensor.get_delegate_identities(), ) # Filter stakes with actual amounts @@ -118,16 +118,16 @@ async def stake_movement_wizard( return None # Display available stakes - _display_available_stakes(available_stakes, ck_hk_identities, old_identities) + _display_available_stakes(available_stakes, ck_hk_identities) # Guide user through the specific operation if operation == "move": return await _guide_move_operation( - subtensor, wallet, available_stakes, ck_hk_identities, old_identities + subtensor, wallet, available_stakes, ck_hk_identities ) elif operation == "transfer": return await _guide_transfer_operation( - subtensor, wallet, available_stakes, ck_hk_identities, old_identities + subtensor, wallet, available_stakes, ck_hk_identities ) elif operation == "swap": return await _guide_swap_operation(subtensor, wallet, available_stakes) @@ -138,7 +138,6 @@ async def stake_movement_wizard( def _display_available_stakes( stakes: list, ck_hk_identities: dict, - old_identities: dict, ): """Display a table of available stakes.""" # Group stakes by hotkey @@ -151,13 +150,7 @@ def _display_available_stakes( # Get identities def get_identity(hotkey_ss58_: str) -> str: - if hk_identity := ck_hk_identities["hotkeys"].get(hotkey_ss58_): - return hk_identity.get("identity", {}).get("name", "") or hk_identity.get( - "display", "~" - ) - elif old_identity := old_identities.get(hotkey_ss58_): - return old_identity.display - return "~" + return get_hotkey_identity_name(ck_hk_identities, hotkey_ss58_) or "~" table = create_table( title=f"\n[{COLOR_PALETTE['GENERAL']['HEADER']}]Your Available Stakes[/{COLOR_PALETTE['GENERAL']['HEADER']}]\n", @@ -193,7 +186,6 @@ async def _guide_move_operation( wallet: Wallet, available_stakes: list, ck_hk_identities: dict, - old_identities: dict, ) -> dict: """Guide user through move operation.""" console.print( @@ -263,7 +255,6 @@ async def _guide_transfer_operation( wallet: Wallet, available_stakes: list, ck_hk_identities: dict, - old_identities: dict, ) -> dict: """Guide user through transfer operation.""" console.print( diff --git a/bittensor_cli/src/commands/subnets/subnets.py b/bittensor_cli/src/commands/subnets/subnets.py index fcbc7dc03..900887aec 100644 --- a/bittensor_cli/src/commands/subnets/subnets.py +++ b/bittensor_cli/src/commands/subnets/subnets.py @@ -1061,13 +1061,11 @@ async def show_root(): all_subnets, root_state, identities, - old_identities, root_claim_types, ) = await asyncio.gather( subtensor.all_subnets(block_hash=block_hash), subtensor.get_subnet_state(netuid=0, block_hash=block_hash), subtensor.query_all_identities(block_hash=block_hash), - subtensor.get_delegate_identities(block_hash=block_hash), subtensor.get_all_coldkeys_claim_type(block_hash=block_hash), ) root_info = next((s for s in all_subnets if s.netuid == 0), None) @@ -1146,12 +1144,7 @@ async def show_root(): coldkey_identity = identities.get(root_state.coldkeys[idx], {}).get( "name", "" ) - hotkey_identity = old_identities.get(root_state.hotkeys[idx]) - validator_identity = ( - coldkey_identity - if coldkey_identity - else (hotkey_identity.display if hotkey_identity else "") - ) + validator_identity = coldkey_identity coldkey_ss58 = root_state.coldkeys[idx] claim_type_info = root_claim_types.get(coldkey_ss58, {"type": "Swap"}) @@ -1256,12 +1249,7 @@ async def show_root(): coldkey_identity = identities.get( root_state.coldkeys[original_idx], {} ).get("name", "") - hotkey_identity = old_identities.get(selected_hotkey) - validator_identity = ( - coldkey_identity - if coldkey_identity - else (hotkey_identity.display if hotkey_identity else "") - ) + validator_identity = coldkey_identity identity_str = f" ({validator_identity})" if validator_identity else "" console.print( @@ -1282,14 +1270,12 @@ async def show_subnet( ( subnet_info, identities, - old_identities, current_burn_cost, root_claim_types, ema_tao_inflow, ) = await asyncio.gather( subtensor.subnet(netuid=netuid_, block_hash=block_hash), subtensor.query_all_identities(block_hash=block_hash), - subtensor.get_delegate_identities(block_hash=block_hash), subtensor.get_hyperparameter( param_name="Burn", netuid=netuid_, block_hash=block_hash ), @@ -1340,12 +1326,6 @@ async def show_subnet( owner_hotkeys.append(subnet_info.owner_hotkey) owner_identity = identities.get(subnet_info.owner_coldkey, {}).get("name", "") - if not owner_identity: - # If no coldkey identity found, try each owner hotkey - for hotkey in owner_hotkeys: - if hotkey_identity := old_identities.get(hotkey): - owner_identity = hotkey_identity.display - break sorted_indices = sorted( range(len(metagraph_info.hotkeys)), @@ -1373,12 +1353,7 @@ async def show_subnet( coldkey_identity = identities.get(metagraph_info.coldkeys[idx], {}).get( "name", "" ) - hotkey_identity = old_identities.get(metagraph_info.hotkeys[idx]) - uid_identity = ( - coldkey_identity - if coldkey_identity - else (hotkey_identity.display if hotkey_identity else "~") - ) + uid_identity = coldkey_identity or "~" if ( metagraph_info.coldkeys[idx] == subnet_info.owner_coldkey diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index 6fb51e4bb..898375a51 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -15,7 +15,6 @@ HYPERPARAMS_MODULE, HYPERPARAMS_METADATA, RootSudoOnly, - DelegatesDetails, COLOR_PALETTE, ) from bittensor_cli.src.bittensor.balances import Balance @@ -38,6 +37,7 @@ string_to_u64, get_hotkey_pub_ss58, print_extrinsic_id, + get_hotkey_identity_name, ) if TYPE_CHECKING: @@ -730,22 +730,24 @@ async def get_proposal_call_data(p_hash: str) -> Optional[GenericCall]: def display_votes( - vote_data: "ProposalVoteData", delegate_info: dict[str, DelegatesDetails] + vote_data: "ProposalVoteData", hotkey_identity_map: dict[str, dict] ) -> str: vote_list = list() for address in vote_data.ayes: + display_name = get_hotkey_identity_name(hotkey_identity_map, address) or address vote_list.append( "{}: {}".format( - delegate_info[address].display if address in delegate_info else address, + display_name, "[bold green]Aye[/bold green]", ) ) for address in vote_data.nays: + display_name = get_hotkey_identity_name(hotkey_identity_map, address) or address vote_list.append( "{}: {}".format( - delegate_info[address].display if address in delegate_info else address, + display_name, "[bold red]Nay[/bold red]", ) ) @@ -754,14 +756,14 @@ def display_votes( def serialize_vote_data( - vote_data: "ProposalVoteData", delegate_info: dict[str, DelegatesDetails] + vote_data: "ProposalVoteData", hotkey_identity_map: dict[str, dict] ) -> list[dict[str, bool]]: vote_list = {} for address in vote_data.ayes: - f_add = delegate_info[address].display if address in delegate_info else address + f_add = get_hotkey_identity_name(hotkey_identity_map, address) or address vote_list[f_add] = True for address in vote_data.nays: - f_add = delegate_info[address].display if address in delegate_info else address + f_add = get_hotkey_identity_name(hotkey_identity_map, address) or address vote_list[f_add] = False return vote_list @@ -1216,9 +1218,8 @@ async def get_senate( senate_members = await _get_senate_members(subtensor) print_verbose("Fetching member details from Github and on-chain identities") - delegate_info: dict[ - str, DelegatesDetails - ] = await subtensor.get_delegate_identities() + hotkey_identity_map = await subtensor.fetch_coldkey_hotkey_identities() + hotkey_identity_map = hotkey_identity_map or {"hotkeys": {}, "coldkeys": {}} table = Table( Column( @@ -1241,11 +1242,7 @@ async def get_senate( dict_output = [] for ss58_address in senate_members: - member_name = ( - delegate_info[ss58_address].display - if ss58_address in delegate_info - else "~" - ) + member_name = get_hotkey_identity_name(hotkey_identity_map, ss58_address) or "~" table.add_row( member_name, ss58_address, @@ -1271,9 +1268,10 @@ async def proposals( subtensor.substrate.get_block_number(block_hash), ) - registered_delegate_info: dict[ - str, DelegatesDetails - ] = await subtensor.get_delegate_identities() + hotkey_identity_map = await subtensor.fetch_coldkey_hotkey_identities( + block_hash=block_hash + ) + hotkey_identity_map = hotkey_identity_map or {"hotkeys": {}, "coldkeys": {}} title = ( f"[bold #4196D6]Bittensor Governance Proposals[/bold #4196D6]\n" @@ -1329,7 +1327,7 @@ async def proposals( str(vote_data.threshold), f"{len(vote_data.ayes)} ({ayes_threshold:.2f}%)", f"{len(vote_data.nays)} ({nays_threshold:.2f}%)", - display_votes(vote_data, registered_delegate_info), + display_votes(vote_data, hotkey_identity_map), vote_end_cell, f_call_data, ) @@ -1339,7 +1337,7 @@ async def proposals( "threshold": vote_data.threshold, "ayes": len(vote_data.ayes), "nays": len(vote_data.nays), - "votes": serialize_vote_data(vote_data, registered_delegate_info), + "votes": serialize_vote_data(vote_data, hotkey_identity_map), "end": vote_data.end, "call_data": f_call_data, } diff --git a/bittensor_cli/src/commands/view.py b/bittensor_cli/src/commands/view.py index 26bb3eb95..94cfe1546 100644 --- a/bittensor_cli/src/commands/view.py +++ b/bittensor_cli/src/commands/view.py @@ -7,7 +7,13 @@ from bittensor_cli.src.bittensor.balances import Balance from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface -from bittensor_cli.src.bittensor.utils import console, WalletLike, jinja_env +from bittensor_cli.src.bittensor.utils import ( + console, + WalletLike, + jinja_env, + get_hotkey_identity_name, + get_coldkey_identity_name, +) from bittensor_wallet import Wallet from bittensor_cli.src import defaults @@ -91,30 +97,22 @@ def int_to_ip(int_val: int) -> str: def get_identity( hotkey_ss58: str, identities: dict, - old_identities: dict, truncate_length: int = 4, return_bool: bool = False, lookup_hk: bool = True, ) -> str: - """Fetch identity of hotkey from both sources""" + """Fetch identity from the V2-backed coldkey/hotkey identity map.""" if lookup_hk: - if hk_identity := identities["hotkeys"].get(hotkey_ss58): - return hk_identity.get("identity", {}).get("name", "") or hk_identity.get( - "display", "~" - ) + if display_name := get_hotkey_identity_name(identities, hotkey_ss58): + return display_name else: - if ck_identity := identities["coldkeys"].get(hotkey_ss58): - return ck_identity.get("identity", {}).get("name", "") or ck_identity.get( - "display", "~" - ) + if display_name := get_coldkey_identity_name(identities, hotkey_ss58): + return display_name - if old_identity := old_identities.get(hotkey_ss58): - return old_identity.display + if return_bool: + return False else: - if return_bool: - return False - else: - return f"{hotkey_ss58[:truncate_length]}...{hotkey_ss58[-truncate_length:]}" + return f"{hotkey_ss58[:truncate_length]}...{hotkey_ss58[-truncate_length:]}" async def fetch_subnet_data( @@ -131,7 +129,6 @@ async def fetch_subnet_data( metagraphs_info, subnets_info, ck_hk_identities, - old_identities, block_number, ) = await asyncio.gather( subtensor.get_balance(wallet.coldkeypub.ss58_address, block_hash=block_hash), @@ -141,7 +138,6 @@ async def fetch_subnet_data( subtensor.get_all_metagraphs_info(block_hash=block_hash), subtensor.all_subnets(block_hash=block_hash), subtensor.fetch_coldkey_hotkey_identities(block_hash=block_hash), - subtensor.get_delegate_identities(block_hash=block_hash), subtensor.substrate.get_block_number(block_hash=block_hash), ) @@ -151,7 +147,6 @@ async def fetch_subnet_data( "metagraphs_info": metagraphs_info, "subnets_info": subnets_info, "ck_hk_identities": ck_hk_identities, - "old_identities": old_identities, "wallet": wallet, "block_number": block_number, } @@ -166,7 +161,6 @@ def process_subnet_data(raw_data: dict[str, Any]) -> dict[str, Any]: metagraphs_info = raw_data["metagraphs_info"] subnets_info = raw_data["subnets_info"] ck_hk_identities = raw_data["ck_hk_identities"] - old_identities = raw_data["old_identities"] wallet = raw_data["wallet"] block_number = raw_data["block_number"] @@ -189,7 +183,7 @@ def process_subnet_data(raw_data: dict[str, Any]) -> dict[str, Any]: { "hotkey": stake.hotkey_ss58, "hotkey_identity": get_identity( - stake.hotkey_ss58, ck_hk_identities, old_identities + stake.hotkey_ss58, ck_hk_identities ), "amount": stake.stake.tao, "emission": stake.emission.tao, @@ -252,9 +246,7 @@ def process_subnet_data(raw_data: dict[str, Any]) -> dict[str, Any]: # Add identities for hotkey in meta_info.hotkeys: - identity = get_identity( - hotkey, ck_hk_identities, old_identities, truncate_length=2 - ) + identity = get_identity(hotkey, ck_hk_identities, truncate_length=2) metagraph_info["updated_identities"].append(identity) # Balance conversion @@ -306,7 +298,6 @@ def process_subnet_data(raw_data: dict[str, Any]) -> dict[str, Any]: wallet_identity = get_identity( wallet.coldkeypub.ss58_address, ck_hk_identities, - old_identities, return_bool=True, lookup_hk=False, ) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index eddf9d611..fbe48fcac 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -1571,10 +1571,10 @@ def delegate_row_maker( for d_, staked in delegates_: if not staked.tao > 0: continue - if d_.hotkey_ss58 in registered_delegate_info: - delegate_name = registered_delegate_info[d_.hotkey_ss58].display - else: - delegate_name = d_.hotkey_ss58 + delegate_name = ( + utils.get_hotkey_identity_name(delegate_identity_map, d_.hotkey_ss58) + or d_.hotkey_ss58 + ) yield ( [""] * 2 + [ @@ -1634,12 +1634,15 @@ def neuron_row_maker( block_hash=block_hash, ) # bittensor.logging.debug(f"Netuids to check: {all_netuids}") - with console.status("Pulling delegates info...", spinner="aesthetic"): - registered_delegate_info = await subtensor.get_delegate_identities() - if not registered_delegate_info: + with console.status("Pulling identity info...", spinner="aesthetic"): + delegate_identity_map = await subtensor.fetch_coldkey_hotkey_identities( + block_hash=block_hash + ) + if not delegate_identity_map: console.print( - ":warning:[yellow]Could not get delegate info from chain.[/yellow]" + ":warning:[yellow]Could not get identity info from chain.[/yellow]" ) + delegate_identity_map = delegate_identity_map or {"hotkeys": {}, "coldkeys": {}} table = Table( Column("[bold white]Coldkey", style="dark_orange"),