bittensor.core.chain_data.utils#

Chain data helper functions and data.

Classes#

ChainDataType

Generic enumeration.

Functions#

decode_account_id(account_id_bytes)

Decodes an AccountId from bytes to a Base64 string using SS58 encoding.

decode_metadata(metadata)

from_scale_encoding(input_, type_name[, is_vec, is_option])

Decodes input_ data from SCALE encoding based on the specified type name and modifiers.

from_scale_encoding_using_type_string(input_, type_string)

Decodes SCALE encoded data to a dictionary based on the provided type string.

process_stake_data(stake_data)

Processes stake data to decode account IDs and convert stakes from rao to Balance objects.

Module Contents#

class bittensor.core.chain_data.utils.ChainDataType#

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

AccountId = 10#
AxonInfo = 16#
ChainIdentity = 15#
DelegateInfo = 3#
DelegatedInfo = 5#
DynamicInfo = 12#
IPInfo = 7#
MetagraphInfo = 14#
NeuronInfo = 1#
NeuronInfoLite = 4#
ScheduledColdkeySwapInfo = 9#
StakeInfo = 6#
SubnetHyperparameters = 8#
SubnetIdentity = 13#
SubnetInfo = 2#
SubnetState = 11#
bittensor.core.chain_data.utils.decode_account_id(account_id_bytes)#

Decodes an AccountId from bytes to a Base64 string using SS58 encoding.

Parameters:

account_id_bytes (bytes) – The AccountId in bytes that needs to be decoded.

Returns:

The decoded AccountId as a Base64 string.

Return type:

str

bittensor.core.chain_data.utils.decode_metadata(metadata)#
Parameters:

metadata (dict)

Return type:

str

bittensor.core.chain_data.utils.from_scale_encoding(input_, type_name, is_vec=False, is_option=False)#

Decodes input_ data from SCALE encoding based on the specified type name and modifiers.

Parameters:
  • input (Union[List[int], bytes, ScaleBytes]) – The input_ data to decode.

  • type_name (ChainDataType) – The type of data being decoded.

  • is_vec (bool) – Whether the data is a vector of the specified type. Default is False.

  • is_option (bool) – Whether the data is an optional value of the specified type. Default is False.

  • input_ (Union[list[int], bytes, scalecodec.base.ScaleBytes])

Returns:

The decoded data as a dictionary, or None if the decoding fails.

Return type:

Optional[dict]

bittensor.core.chain_data.utils.from_scale_encoding_using_type_string(input_, type_string)#

Decodes SCALE encoded data to a dictionary based on the provided type string.

Parameters:
  • input (Union[List[int], bytes, ScaleBytes]) – The SCALE encoded input data.

  • type_string (str) – The type string defining the structure of the data.

  • input_ (Union[list[int], bytes, scalecodec.base.ScaleBytes])

Returns:

The decoded data as a dictionary, or None if the decoding fails.

Return type:

Optional[dict]

Raises:

TypeError – If the input_ is not a list[int], bytes, or ScaleBytes.

bittensor.core.chain_data.utils.process_stake_data(stake_data)#

Processes stake data to decode account IDs and convert stakes from rao to Balance objects.

Parameters:

stake_data (list) – A list of tuples where each tuple contains an account ID in bytes and a stake in rao.

Returns:

A dictionary with account IDs as keys and their corresponding Balance objects as values.

Return type:

dict