Skip to content

Commit fdb5342

Browse files
committed
Added get_stake_for_hotkey to AsyncSubtensor and Subtensor
1 parent ccd8a00 commit fdb5342

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

bittensor/core/async_subtensor.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,40 @@ async def get_stake_for_coldkey(
16651665

16661666
get_stake_info_for_coldkey = get_stake_for_coldkey
16671667

1668+
async def get_stake_for_hotkey(
1669+
self,
1670+
hotkey_ss58: str,
1671+
netuid: int,
1672+
block: Optional[int] = None,
1673+
block_hash: Optional[str] = None,
1674+
reuse_block: bool = False,
1675+
) -> Balance:
1676+
"""
1677+
Retrieves the stake information for a given hotkey.
1678+
1679+
Args:
1680+
hotkey_ss58: The SS58 address of the hotkey.
1681+
netuid: The subnet ID to query for.
1682+
block: The block number at which to query the stake information. Do not specify if also specifying
1683+
block_hash or reuse_block
1684+
block_hash: The hash of the blockchain block number for the query. Do not specify if also specifying block
1685+
or reuse_block
1686+
reuse_block: Whether to reuse for this query the last-used block. Do not specify if also specifying block
1687+
or block_hash.
1688+
"""
1689+
hotkey_alpha_query = await self.query_subtensor(
1690+
name="TotalHotkeyAlpha",
1691+
params=[hotkey_ss58, netuid],
1692+
block=block,
1693+
block_hash=block_hash,
1694+
reuse_block=reuse_block,
1695+
)
1696+
balance = Balance.from_rao(hotkey_alpha_query.value)
1697+
balance.set_unit(netuid=netuid)
1698+
return balance
1699+
1700+
get_hotkey_stake = get_stake_for_hotkey
1701+
16681702
async def get_subnet_burn_cost(
16691703
self,
16701704
block: Optional[int] = None,

bittensor/core/subtensor.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
import scalecodec
88
from async_substrate_interface.errors import SubstrateRequestException
9+
from async_substrate_interface.types import ScaleObj
910
from async_substrate_interface.sync_substrate import SubstrateInterface
1011
from async_substrate_interface.utils import json
1112
from numpy.typing import NDArray
@@ -91,7 +92,6 @@
9192
if TYPE_CHECKING:
9293
from bittensor_wallet import Wallet
9394
from async_substrate_interface.sync_substrate import QueryMapResult
94-
from async_substrate_interface.types import ScaleObj
9595
from scalecodec.types import GenericCall
9696

9797

@@ -1281,6 +1281,28 @@ def get_stake_for_coldkey(
12811281

12821282
get_stake_info_for_coldkey = get_stake_for_coldkey
12831283

1284+
def get_stake_for_hotkey(
1285+
self, hotkey_ss58: str, netuid: int, block: Optional[int] = None
1286+
) -> Balance:
1287+
"""
1288+
Retrieves the stake information for a given hotkey.
1289+
1290+
Args:
1291+
hotkey_ss58: The SS58 address of the hotkey.
1292+
netuid: The subnet ID to query for.
1293+
block: The block number at which to query the stake information. Do not specify if also specifying
1294+
block_hash or reuse_block
1295+
"""
1296+
hotkey_alpha_query = self.query_subtensor(
1297+
name="TotalHotkeyAlpha", params=[hotkey_ss58, netuid], block=block
1298+
)
1299+
hotkey_alpha = cast(ScaleObj, hotkey_alpha_query)
1300+
balance = Balance.from_rao(hotkey_alpha.value)
1301+
balance.set_unit(netuid=netuid)
1302+
return balance
1303+
1304+
get_hotkey_stake = get_stake_for_hotkey
1305+
12841306
def get_subnet_burn_cost(self, block: Optional[int] = None) -> Optional[Balance]:
12851307
"""
12861308
Retrieves the burn cost for registering a new subnet within the Bittensor network. This cost represents the

0 commit comments

Comments
 (0)