|
16 | 16 |
|
17 | 17 | from bittensor.core.chain_data import (
|
18 | 18 | DelegateInfo,
|
19 |
| - StakeInfo, |
| 19 | + DynamicInfo, |
20 | 20 | MetagraphInfo,
|
21 | 21 | NeuronInfoLite,
|
22 | 22 | NeuronInfo,
|
23 | 23 | ProposalVoteData,
|
| 24 | + StakeInfo, |
| 25 | + SelectiveMetagraphIndex, |
24 | 26 | SubnetHyperparameters,
|
25 | 27 | SubnetIdentity,
|
26 | 28 | SubnetInfo,
|
27 | 29 | WeightCommitInfo,
|
28 | 30 | decode_account_id,
|
29 |
| - DynamicInfo, |
30 | 31 | )
|
31 | 32 | from bittensor.core.chain_data.chain_identity import ChainIdentity
|
32 | 33 | from bittensor.core.chain_data.delegate_info import DelegatedInfo
|
@@ -1470,32 +1471,56 @@ async def get_minimum_required_stake(self):
|
1470 | 1471 | async def get_metagraph_info(
|
1471 | 1472 | self,
|
1472 | 1473 | netuid: int,
|
| 1474 | + field_indices: Optional[list["SelectiveMetagraphIndex"]] = None, |
1473 | 1475 | block: Optional[int] = None,
|
1474 | 1476 | block_hash: Optional[str] = None,
|
1475 | 1477 | reuse_block: bool = False,
|
1476 | 1478 | ) -> Optional[MetagraphInfo]:
|
1477 | 1479 | """
|
1478 |
| - Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid) |
| 1480 | + Retrieves full or partial metagraph information for the specified subnet (netuid). |
1479 | 1481 |
|
1480 | 1482 | Arguments:
|
1481 |
| - netuid: The NetUID of the subnet. |
| 1483 | + netuid (int): The NetUID of the subnet to query. |
| 1484 | + field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values |
| 1485 | + specifying which fields to retrieve. If not provided, all available fields will be returned. |
1482 | 1486 | block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or
|
1483 | 1487 | reuse_block
|
1484 | 1488 | block_hash: The hash of blockchain block number for the query. Do not specify if using
|
1485 | 1489 | block or reuse_block
|
1486 | 1490 | reuse_block: Whether to reuse the last-used block hash. Do not set if using block_hash or block.
|
1487 | 1491 |
|
1488 | 1492 | Returns:
|
1489 |
| - MetagraphInfo dataclass |
| 1493 | + Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet |
| 1494 | + with the given netuid does not exist. |
| 1495 | +
|
| 1496 | + Example: |
| 1497 | + meta_info = await subtensor.get_metagraph_info(netuid=2) |
| 1498 | +
|
| 1499 | + partial_meta_info = await subtensor.get_metagraph_info( |
| 1500 | + netuid=2, |
| 1501 | + field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys] |
| 1502 | + ) |
1490 | 1503 | """
|
| 1504 | + indexes = SelectiveMetagraphIndex.all_indices() |
| 1505 | + |
| 1506 | + if field_indices: |
| 1507 | + if isinstance(field_indices, list) and all( |
| 1508 | + isinstance(f, SelectiveMetagraphIndex) for f in field_indices |
| 1509 | + ): |
| 1510 | + indexes = [f.value for f in field_indices] |
| 1511 | + else: |
| 1512 | + raise ValueError( |
| 1513 | + "`field_indices` must be a list of SelectiveMetagraphIndex items." |
| 1514 | + ) |
| 1515 | + |
1491 | 1516 | block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
|
1492 | 1517 | if not block_hash and reuse_block:
|
1493 | 1518 | block_hash = self.substrate.last_block_hash
|
1494 | 1519 |
|
1495 | 1520 | query = await self.substrate.runtime_call(
|
1496 | 1521 | "SubnetInfoRuntimeApi",
|
1497 |
| - "get_metagraph", |
1498 |
| - params=[netuid], |
| 1522 | + "get_selective_metagraph", |
| 1523 | + params=[netuid, indexes if 0 in indexes else [0] + indexes], |
1499 | 1524 | block_hash=block_hash,
|
1500 | 1525 | )
|
1501 | 1526 | if query.value is None:
|
@@ -4177,7 +4202,7 @@ async def unstake(
|
4177 | 4202 | removed.
|
4178 | 4203 | hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey account to unstake from.
|
4179 | 4204 | netuid (Optional[int]): The unique identifier of the subnet.
|
4180 |
| - amount (Balance): The amount of TAO to unstake. If not specified, unstakes all. |
| 4205 | + amount (Balance): The amount of alpha to unstake. If not specified, unstakes all. |
4181 | 4206 | wait_for_inclusion (bool): Waits for the transaction to be included in a block.
|
4182 | 4207 | wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
|
4183 | 4208 | safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake
|
|
0 commit comments