@@ -3061,7 +3061,7 @@ async def set_reveal_commitment(
30613061 async def subnet (
30623062 self ,
30633063 netuid : int ,
3064- block : int = None ,
3064+ block : Optional [ int ] = None ,
30653065 block_hash : Optional [str ] = None ,
30663066 reuse_block : bool = False ,
30673067 ) -> Optional [DynamicInfo ]:
@@ -3071,23 +3071,26 @@ async def subnet(
30713071 Args:
30723072 netuid (int): The unique identifier of the subnet.
30733073 block (Optional[int]): The block number to get the subnets at.
3074- block_hash (str): The hash of the blockchain block number for the query.
3074+ block_hash (Optional[ str] ): The hash of the blockchain block number for the query.
30753075 reuse_block (bool): Whether to reuse the last-used blockchain block hash.
30763076
30773077 Returns:
30783078 Optional[DynamicInfo]: A DynamicInfo object, containing detailed information about a subnet.
30793079 """
30803080 block_hash = await self .determine_block_hash (block , block_hash , reuse_block )
3081+
30813082 if not block_hash and reuse_block :
30823083 block_hash = self .substrate .last_block_hash
3084+
30833085 query = await self .substrate .runtime_call (
30843086 "SubnetInfoRuntimeApi" ,
30853087 "get_dynamic_info" ,
30863088 params = [netuid ],
30873089 block_hash = block_hash ,
30883090 )
3089- subnet = DynamicInfo .from_dict (query .decode ())
3090- return subnet
3091+
3092+ if isinstance (decoded := query .decode (), dict ):
3093+ return DynamicInfo .from_dict (decoded )
30913094
30923095 async def subnet_exists (
30933096 self ,
@@ -3236,6 +3239,7 @@ async def handler(block_data: dict):
32363239
32373240 current_block = await self .substrate .get_block ()
32383241 current_block_hash = current_block .get ("header" , {}).get ("hash" )
3242+
32393243 if block is not None :
32403244 target_block = block
32413245 else :
@@ -3333,15 +3337,14 @@ async def get_timestamp(
33333337 Returns:
33343338 datetime object for the timestamp of the block
33353339 """
3336- unix = (
3337- await self .query_module (
3338- "Timestamp" ,
3339- "Now" ,
3340- block = block ,
3341- block_hash = block_hash ,
3342- reuse_block = reuse_block ,
3343- )
3344- ).value
3340+ res = await self .query_module (
3341+ "Timestamp" ,
3342+ "Now" ,
3343+ block = block ,
3344+ block_hash = block_hash ,
3345+ reuse_block = reuse_block ,
3346+ )
3347+ unix = res .value
33453348 return datetime .fromtimestamp (unix / 1000 , tz = timezone .utc )
33463349
33473350 async def get_subnet_owner_hotkey (
0 commit comments