Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/adds total stake functions #2537

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Changes from 2 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
34 changes: 34 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,40 @@ def neurons(self, netuid: int, block: Optional[int] = None) -> list["NeuronInfo"

return neurons

def get_total_stake_for_coldkey(
self, ss58_address: str, block: Optional[int] = None
) -> Optional["Balance"]:
"""Retrieves the total stake held by a coldkey across all associated hotkeys, including delegated stakes.

Args:
ss58_address (str): The SS58 address of the coldkey account.
block (Optional[int]): The blockchain block number at which to perform the query.

Returns:
Optional[Balance]: The total stake amount held by the coldkey, or None if the query fails.
"""
result = self.query_subtensor("TotalColdkeyStake", block, [ss58_address])
if not hasattr(result, "value") or result is None:
ibraheem-opentensor marked this conversation as resolved.
Show resolved Hide resolved
return None
return Balance.from_rao(result.value)

def get_total_stake_for_hotkey(
self, ss58_address: str, block: Optional[int] = None
) -> Optional["Balance"]:
"""Retrieves the total stake associated with a hotkey.

Args:
ss58_address (str): The SS58 address of the hotkey account.
block (Optional[int]): The blockchain block number at which to perform the query.

Returns:
Optional[Balance]: The total stake amount held by the hotkey, or None if the query fails.
"""
result = self.query_subtensor("TotalHotkeyStake", block, [ss58_address])
if not hasattr(result, "value") or result is None:
ibraheem-opentensor marked this conversation as resolved.
Show resolved Hide resolved
return None
return Balance.from_rao(result.value)

def get_total_subnets(self, block: Optional[int] = None) -> Optional[int]:
"""
Retrieves the total number of subnets within the Bittensor network as of a specific blockchain block.
Expand Down
Loading