Skip to content

Commit b0cf115

Browse files
author
Roman
committed
add new methods to subtensor
1 parent 43226b5 commit b0cf115

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

bittensor/core/subtensor.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ def all_subnets(self, block: Optional[int] = None) -> Optional[list["DynamicInfo
388388
)
389389
return DynamicInfo.list_from_dicts(query.decode())
390390

391+
def blocks_since_last_step(
392+
self, netuid: int, block: Optional[int] = None
393+
) -> Optional[int]:
394+
"""Returns number of blocks since the last epoch of the subnet.
395+
396+
Arguments:
397+
netuid (int): The unique identifier of the subnetwork.
398+
block: the block number for this query.
399+
400+
Returns:
401+
block number of the last step in the subnet.
402+
"""
403+
query = self.query_subtensor(
404+
name="BlocksSinceLastStep", block=block, params=[netuid]
405+
)
406+
return query.value if query is not None and hasattr(query, "value") else query
407+
391408
def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]:
392409
"""
393410
Returns the number of blocks since the last update for a specific UID in the subnetwork.
@@ -2575,6 +2592,46 @@ def get_timestamp(self, block: Optional[int] = None) -> datetime:
25752592
unix = cast(ScaleObj, self.query_module("Timestamp", "Now", block=block)).value
25762593
return datetime.fromtimestamp(unix / 1000, tz=timezone.utc)
25772594

2595+
def get_subnet_owner_hotkey(
2596+
self, netuid: int, block: Optional[int] = None
2597+
) -> Optional[str]:
2598+
"""
2599+
Retrieves the hotkey of the subnet owner for a given network UID.
2600+
2601+
This function queries the subtensor network to fetch the hotkey of the owner of a subnet specified by its
2602+
netuid. If no data is found or the query fails, the function returns None.
2603+
2604+
Arguments:
2605+
netuid: The network UID of the subnet to fetch the owner's hotkey for.
2606+
block: The specific block number to query the data from.
2607+
2608+
Returns:
2609+
The hotkey of the subnet owner if available; None otherwise.
2610+
"""
2611+
return self.query_subtensor(
2612+
name="SubnetOwnerHotkey", params=[netuid], block=block
2613+
)
2614+
2615+
def get_subnet_validator_permits(
2616+
self, netuid: int, block: Optional[int] = None
2617+
) -> Optional[list[bool]]:
2618+
"""
2619+
Retrieves the list of validator permits for a given subnet as boolean values.
2620+
2621+
Arguments:
2622+
netuid: The unique identifier of the subnetwork.
2623+
block: The blockchain block number for the query.
2624+
2625+
Returns:
2626+
A list of boolean values representing validator permits, or None if not available.
2627+
"""
2628+
query = self.query_subtensor(
2629+
name="ValidatorPermit",
2630+
params=[netuid],
2631+
block=block,
2632+
)
2633+
return query.value if query is not None and hasattr(query, "value") else query
2634+
25782635
# Extrinsics helper ================================================================================================
25792636

25802637
def sign_and_send_extrinsic(
@@ -2598,6 +2655,9 @@ def sign_and_send_extrinsic(
25982655
wait_for_inclusion (bool): whether to wait until the extrinsic call is included on the chain
25992656
wait_for_finalization (bool): whether to wait until the extrinsic call is finalized on the chain
26002657
sign_with: the wallet's keypair to use for the signing. Options are "coldkey", "hotkey", "coldkeypub"
2658+
use_nonce: unique identifier for the transaction related with hot/coldkey.
2659+
period: the period of the transaction as ERA part for transaction. Means how many blocks the transaction will be valid for.
2660+
nonce_key: the type on nonce to use. Options are "hotkey" or "coldkey".
26012661
raise_error: raises relevant exception rather than returning `False` if unsuccessful.
26022662
26032663
Returns:

0 commit comments

Comments
 (0)