11import asyncio
22import copy
3- from datetime import datetime , timezone
43import ssl
4+ from datetime import datetime , timezone
55from functools import partial
66from typing import Optional , Any , Union , Iterable , TYPE_CHECKING
77
88import asyncstdlib as a
99import numpy as np
1010import scalecodec
1111from async_substrate_interface import AsyncSubstrateInterface
12+ from bittensor_commit_reveal import get_encrypted_commitment
1213from bittensor_wallet .utils import SS58_FORMAT
1314from numpy .typing import NDArray
1415from scalecodec import GenericCall
2728 decode_account_id ,
2829 DynamicInfo ,
2930)
30- from bittensor_commit_reveal import get_encrypted_commitment
3131from bittensor .core .chain_data .chain_identity import ChainIdentity
3232from bittensor .core .chain_data .delegate_info import DelegatedInfo
3333from bittensor .core .chain_data .utils import (
3838from bittensor .core .config import Config
3939from bittensor .core .errors import ChainError , SubstrateRequestException
4040from bittensor .core .extrinsics .asyncex .commit_reveal import commit_reveal_v3_extrinsic
41+ from bittensor .core .extrinsics .asyncex .move_stake import (
42+ transfer_stake_extrinsic ,
43+ swap_stake_extrinsic ,
44+ move_stake_extrinsic ,
45+ )
4146from bittensor .core .extrinsics .asyncex .registration import (
4247 burned_register_extrinsic ,
4348 register_extrinsic ,
4449 register_subnet_extrinsic ,
4550 set_subnet_identity_extrinsic ,
4651)
47- from bittensor .core .extrinsics .asyncex .move_stake import (
48- transfer_stake_extrinsic ,
49- swap_stake_extrinsic ,
50- move_stake_extrinsic ,
51- )
5252from bittensor .core .extrinsics .asyncex .root import (
5353 set_root_weights_extrinsic ,
5454 root_register_extrinsic ,
8484 decode_hex_identity_dict ,
8585 float_to_u64 ,
8686 format_error_message ,
87+ is_valid_ss58_address ,
8788 torch ,
8889 u16_normalized_float ,
8990 u64_normalized_float ,
@@ -1064,14 +1065,14 @@ async def get_all_commitments(
10641065 result [decode_account_id (id_ [0 ])] = decode_metadata (value )
10651066 return result
10661067
1067- async def get_revealed_commitment (
1068+ async def get_revealed_commitment_by_hotkey (
10681069 self ,
10691070 netuid : int ,
10701071 hotkey_ss58_address : Optional [str ] = None ,
10711072 block : Optional [int ] = None ,
10721073 block_hash : Optional [str ] = None ,
10731074 reuse_block : bool = False ,
1074- ) -> Optional [tuple [int , str ]]:
1075+ ) -> Optional [tuple [tuple [ int , str ], ... ]]:
10751076 """Returns hotkey related revealed commitment for a given netuid.
10761077
10771078 Arguments:
@@ -1084,6 +1085,9 @@ async def get_revealed_commitment(
10841085 Returns:
10851086 result (tuple[int, str): A tuple of reveal block and commitment message.
10861087 """
1088+ if not is_valid_ss58_address (address = hotkey_ss58_address ):
1089+ raise ValueError (f"Invalid ss58 address { hotkey_ss58_address } provided." )
1090+
10871091 query = await self .query_module (
10881092 module = "Commitments" ,
10891093 name = "RevealedCommitments" ,
@@ -1092,15 +1096,50 @@ async def get_revealed_commitment(
10921096 block_hash = block_hash ,
10931097 reuse_block = reuse_block ,
10941098 )
1095- return decode_revealed_commitment (query )
1099+ if query is None :
1100+ return None
1101+ return tuple (decode_revealed_commitment (pair ) for pair in query )
1102+
1103+ async def get_revealed_commitment (
1104+ self ,
1105+ netuid : int ,
1106+ uid : int ,
1107+ block : Optional [int ] = None ,
1108+ ) -> Optional [tuple [tuple [int , str ], ...]]:
1109+ """Returns uid related revealed commitment for a given netuid.
1110+
1111+ Arguments:
1112+ netuid (int): The unique identifier of the subnetwork.
1113+ uid (int): The neuron uid to retrieve the commitment from.
1114+ block (Optional[int]): The block number to retrieve the commitment from. Default is ``None``.
1115+
1116+ Returns:
1117+ result (Optional[tuple[int, str]]: A tuple of reveal block and commitment message.
1118+
1119+ Example of result:
1120+ ( (12, "Alice message 1"), (152, "Alice message 2") )
1121+ ( (12, "Bob message 1"), (147, "Bob message 2") )
1122+ """
1123+ try :
1124+ meta_info = await self .get_metagraph_info (netuid , block = block )
1125+ if meta_info :
1126+ hotkey_ss58_address = meta_info .hotkeys [uid ]
1127+ else :
1128+ raise ValueError (f"Subnet with netuid { netuid } does not exist." )
1129+ except IndexError :
1130+ raise ValueError (f"Subnet { netuid } does not have a neuron with uid { uid } ." )
1131+
1132+ return await self .get_revealed_commitment_by_hotkey (
1133+ netuid = netuid , hotkey_ss58_address = hotkey_ss58_address , block = block
1134+ )
10961135
10971136 async def get_all_revealed_commitments (
10981137 self ,
10991138 netuid : int ,
11001139 block : Optional [int ] = None ,
11011140 block_hash : Optional [str ] = None ,
11021141 reuse_block : bool = False ,
1103- ) -> dict [str , tuple [int , str ]]:
1142+ ) -> dict [str , tuple [tuple [ int , str ], ... ]]:
11041143 """Returns all revealed commitments for a given netuid.
11051144
11061145 Arguments:
@@ -1111,6 +1150,12 @@ async def get_all_revealed_commitments(
11111150
11121151 Returns:
11131152 result (dict): A dictionary of all revealed commitments in view {ss58_address: (reveal block, commitment message)}.
1153+
1154+ Example of result:
1155+ {
1156+ "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY": ( (12, "Alice message 1"), (152, "Alice message 2") ),
1157+ "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty": ( (12, "Bob message 1"), (147, "Bob message 2") ),
1158+ }
11141159 """
11151160 query = await self .query_map (
11161161 module = "Commitments" ,
@@ -1122,8 +1167,11 @@ async def get_all_revealed_commitments(
11221167 )
11231168
11241169 result = {}
1125- async for item in query :
1126- result .update (decode_revealed_commitment_with_hotkey (item ))
1170+ async for pair in query :
1171+ hotkey_ss58_address , commitment_message = (
1172+ decode_revealed_commitment_with_hotkey (pair )
1173+ )
1174+ result [hotkey_ss58_address ] = commitment_message
11271175 return result
11281176
11291177 async def get_current_weight_commit_info (
0 commit comments