@@ -973,6 +973,51 @@ async def get_block_hash(self, block: Optional[int] = None) -> str:
973
973
else :
974
974
return await self .substrate .get_chain_head ()
975
975
976
+ async def get_parents (
977
+ self ,
978
+ hotkey : str ,
979
+ netuid : int ,
980
+ block : Optional [int ] = None ,
981
+ block_hash : Optional [str ] = None ,
982
+ reuse_block : bool = False ,
983
+ ) -> tuple [bool , list [tuple [float , str ]], str ]:
984
+ """
985
+ This method retrieves the parent of a given hotkey and netuid. It queries the SubtensorModule's ParentKeys
986
+ storage function to get the children and formats them before returning as a tuple.
987
+
988
+ Arguments:
989
+ hotkey (str): The child hotkey SS58.
990
+ netuid (int): The netuid value.
991
+ block (Optional[int]): The block number for which the children are to be retrieved.
992
+ block_hash (Optional[str]): The hash of the block to retrieve the subnet unique identifiers from.
993
+ reuse_block (bool): Whether to reuse the last-used block hash.
994
+
995
+ Returns:
996
+ A tuple containing a boolean indicating success or failure, a list of formatted
997
+ parents [(proportion, parent)], and an error message (if applicable)
998
+ """
999
+ block_hash = await self .determine_block_hash (block , block_hash , reuse_block )
1000
+ try :
1001
+ parents = await self .substrate .query (
1002
+ module = "SubtensorModule" ,
1003
+ storage_function = "ParentKeys" ,
1004
+ params = [hotkey , netuid ],
1005
+ block_hash = block_hash ,
1006
+ reuse_block_hash = reuse_block ,
1007
+ )
1008
+ if parents :
1009
+ formatted_parents = []
1010
+ for proportion , parent in parents .value :
1011
+ # Convert U64 to int
1012
+ formatted_child = decode_account_id (parent [0 ])
1013
+ normalized_proportion = u64_normalized_float (proportion )
1014
+ formatted_parents .append ((normalized_proportion , formatted_child ))
1015
+ return True , formatted_parents , ""
1016
+ else :
1017
+ return True , [], ""
1018
+ except SubstrateRequestException as e :
1019
+ return False , [], format_error_message (e )
1020
+
976
1021
async def get_children (
977
1022
self ,
978
1023
hotkey : str ,
0 commit comments