bittensor.core.extrinsics.utils#

Module with helper functions for extrinsics.

Functions#

async_submit_extrinsic(subtensor, extrinsic, ...)

Submits an extrinsic to the substrate blockchain and handles potential exceptions.

get_old_stakes(wallet, hotkey_ss58s, netuids, all_stakes)

Retrieve the previous staking balances for a wallet's hotkeys across given netuids.

submit_extrinsic(subtensor, extrinsic, ...)

Submits an extrinsic to the substrate blockchain and handles potential exceptions.

Module Contents#

async bittensor.core.extrinsics.utils.async_submit_extrinsic(subtensor, extrinsic, wait_for_inclusion, wait_for_finalization)#

Submits an extrinsic to the substrate blockchain and handles potential exceptions.

This function attempts to submit an extrinsic to the substrate blockchain with specified options for waiting for inclusion in a block and/or finalization. If an exception occurs during submission, it logs the error and re-raises the exception.

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The AsyncSubtensor instance used to interact with the blockchain.

  • extrinsic (scalecodec.types.GenericExtrinsic) – The extrinsic to be submitted to the blockchain.

  • wait_for_inclusion (bool) – Whether to wait for the extrinsic to be included in a block.

  • wait_for_finalization (bool) – Whether to wait for the extrinsic to be finalized on the blockchain.

Returns:

The response from the substrate after submitting the extrinsic.

Return type:

response

Raises:

SubstrateRequestException – If the submission of the extrinsic fails, the error is logged and re-raised.

bittensor.core.extrinsics.utils.get_old_stakes(wallet, hotkey_ss58s, netuids, all_stakes)#

Retrieve the previous staking balances for a wallet’s hotkeys across given netuids.

This function searches through the provided staking data to find the stake amounts for the specified hotkeys and netuids associated with the wallet’s coldkey. If no match is found for a particular hotkey and netuid combination, a default balance of zero is returned.

Parameters:
  • wallet (Wallet) – The wallet containing the coldkey to compare with stake data.

  • hotkey_ss58s (list[str]) – List of hotkey SS58 addresses for which stakes are retrieved.

  • netuids (list[int]) – List of network unique identifiers (netuids) corresponding to the hotkeys.

  • all_stakes (list[StakeInfo]) – A collection of all staking information to search through.

Returns:

A list of Balances, each representing the stake for a given hotkey and netuid.

Return type:

list[Balance]

bittensor.core.extrinsics.utils.submit_extrinsic(subtensor, extrinsic, wait_for_inclusion, wait_for_finalization)#

Submits an extrinsic to the substrate blockchain and handles potential exceptions.

This function attempts to submit an extrinsic to the substrate blockchain with specified options for waiting for inclusion in a block and/or finalization. If an exception occurs during submission, it logs the error and re-raises the exception.

Parameters:
  • subtensor (bittensor.core.subtensor.Subtensor) – The Subtensor instance used to interact with the blockchain.

  • extrinsic (scalecodec.types.GenericExtrinsic) – The extrinsic to be submitted to the blockchain.

  • wait_for_inclusion (bool) – Whether to wait for the extrinsic to be included in a block.

  • wait_for_finalization (bool) – Whether to wait for the extrinsic to be finalized on the blockchain.

Returns:

The response from the substrate after submitting the extrinsic.

Return type:

response

Raises:

SubstrateRequestException – If the submission of the extrinsic fails, the error is logged and re-raised.