Skip to content

Commit

Permalink
Merge pull request #2456 from opentensor/feat/roman/add_unstake_extri…
Browse files Browse the repository at this point in the history
…nsic

Add staking and unstaking extrinsics
  • Loading branch information
roman-opentensor authored Nov 22, 2024
2 parents 279a82c + 2d12d87 commit d460670
Show file tree
Hide file tree
Showing 6 changed files with 2,253 additions and 469 deletions.
70 changes: 36 additions & 34 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ async def encode_params(

return param_data.to_hex()

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.
Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.
Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
logging.error(f"subnet {netuid} does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

# Common subtensor methods =========================================================================================

async def get_current_block(self) -> int:
"""
Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.
Expand Down Expand Up @@ -663,39 +698,6 @@ async def subnet_exists(
)
return result

async def get_hyperparameter(
self,
param_name: str,
netuid: int,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[Any]:
"""
Retrieves a specified hyperparameter for a specific subnet.
Args:
param_name (str): The name of the hyperparameter to retrieve.
netuid (int): The unique identifier of the subnet.
block_hash (Optional[str]): The hash of blockchain block number for the query.
reuse_block (bool): Whether to reuse the last-used block hash.
Returns:
The value of the specified hyperparameter if the subnet exists, or None
"""
if not await self.subnet_exists(netuid, block_hash):
print("subnet does not exist")
return None

result = await self.substrate.query(
module="SubtensorModule",
storage_function=param_name,
params=[netuid],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)

return result

async def filter_netuids_by_registered_hotkeys(
self,
all_netuids: Iterable[int],
Expand Down Expand Up @@ -1357,7 +1359,7 @@ async def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]
call = await self.get_hyperparameter(param_name="LastUpdate", netuid=netuid)
return None if call is None else await self.get_current_block() - int(call[uid])

# extrinsics
# Extrinsics =======================================================================================================

async def transfer(
self,
Expand Down
Loading

0 comments on commit d460670

Please sign in to comment.