|
16 | 16 | from bittensor import Wallet |
17 | 17 | from bittensor.core.async_subtensor import AsyncSubtensor |
18 | 18 | from bittensor.core.subtensor import Subtensor |
19 | | - from async_substrate_interface import SubstrateInterface, ExtrinsicReceipt |
| 19 | + from async_substrate_interface import ( |
| 20 | + AsyncSubstrateInterface, |
| 21 | + AsyncExtrinsicReceipt, |
| 22 | + SubstrateInterface, |
| 23 | + ExtrinsicReceipt, |
| 24 | + ) |
20 | 25 |
|
21 | 26 |
|
22 | 27 | def get_dynamic_balance(rao: int, netuid: int = 0): |
@@ -274,6 +279,49 @@ def sudo_set_admin_utils( |
274 | 279 | return response.is_success, response.error_message |
275 | 280 |
|
276 | 281 |
|
| 282 | +async def async_sudo_set_admin_utils( |
| 283 | + substrate: "AsyncSubstrateInterface", |
| 284 | + wallet: "Wallet", |
| 285 | + call_function: str, |
| 286 | + call_params: dict, |
| 287 | + call_module: str = "AdminUtils", |
| 288 | +) -> tuple[bool, Optional[dict]]: |
| 289 | + """ |
| 290 | + Wraps the call in sudo to set hyperparameter values using AdminUtils. |
| 291 | +
|
| 292 | + Parameters: |
| 293 | + substrate: Substrate connection. |
| 294 | + wallet: Wallet object with the keypair for signing. |
| 295 | + call_function: The AdminUtils function to call. |
| 296 | + call_params: Parameters for the AdminUtils function. |
| 297 | + call_module: The AdminUtils module to call. Defaults to "AdminUtils". |
| 298 | +
|
| 299 | + Returns: |
| 300 | + tuple: (success status, error details). |
| 301 | + """ |
| 302 | + inner_call = await substrate.compose_call( |
| 303 | + call_module=call_module, |
| 304 | + call_function=call_function, |
| 305 | + call_params=call_params, |
| 306 | + ) |
| 307 | + |
| 308 | + sudo_call = await substrate.compose_call( |
| 309 | + call_module="Sudo", |
| 310 | + call_function="sudo", |
| 311 | + call_params={"call": inner_call}, |
| 312 | + ) |
| 313 | + extrinsic = await substrate.create_signed_extrinsic( |
| 314 | + call=sudo_call, keypair=wallet.coldkey |
| 315 | + ) |
| 316 | + response: "AsyncExtrinsicReceipt" = await substrate.submit_extrinsic( |
| 317 | + extrinsic, |
| 318 | + wait_for_inclusion=True, |
| 319 | + wait_for_finalization=True, |
| 320 | + ) |
| 321 | + |
| 322 | + return await response.is_success, await response.error_message |
| 323 | + |
| 324 | + |
277 | 325 | async def root_set_subtensor_hyperparameter_values( |
278 | 326 | substrate: "SubstrateInterface", |
279 | 327 | wallet: "Wallet", |
|
0 commit comments