Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,7 +3061,7 @@ async def set_reveal_commitment(
async def subnet(
self,
netuid: int,
block: int = None,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[DynamicInfo]:
Expand All @@ -3071,23 +3071,26 @@ async def subnet(
Args:
netuid (int): The unique identifier of the subnet.
block (Optional[int]): The block number to get the subnets at.
block_hash (str): The hash of the blockchain block number for the query.
block_hash (Optional[str]): The hash of the blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used blockchain block hash.

Returns:
Optional[DynamicInfo]: A DynamicInfo object, containing detailed information about a subnet.
"""
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)

if not block_hash and reuse_block:
block_hash = self.substrate.last_block_hash

query = await self.substrate.runtime_call(
"SubnetInfoRuntimeApi",
"get_dynamic_info",
params=[netuid],
block_hash=block_hash,
)
subnet = DynamicInfo.from_dict(query.decode())
return subnet

if isinstance(decoded := query.decode(), dict):
return DynamicInfo.from_dict(decoded)

async def subnet_exists(
self,
Expand Down Expand Up @@ -3236,6 +3239,7 @@ async def handler(block_data: dict):

current_block = await self.substrate.get_block()
current_block_hash = current_block.get("header", {}).get("hash")

if block is not None:
target_block = block
else:
Expand Down Expand Up @@ -3333,15 +3337,14 @@ async def get_timestamp(
Returns:
datetime object for the timestamp of the block
"""
unix = (
await self.query_module(
"Timestamp",
"Now",
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)
).value
res = await self.query_module(
"Timestamp",
"Now",
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)
unix = res.value
return datetime.fromtimestamp(unix / 1000, tz=timezone.utc)

async def get_subnet_owner_hotkey(
Expand Down
2 changes: 2 additions & 0 deletions bittensor/core/chain_data/info_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from bittensor.core.errors import SubstrateRequestException

# NOTE: once Python 3.10+ is required, we can use `typing.Self` instead of this for better ide integration and type hinting.
# This current generic does not play so nice with the inherited type hinting.
T = TypeVar("T", bound="InfoBase")


Expand Down