bittensor.core.chain_data.utils#

Chain data helper functions and data.

Classes#

ChainDataType

Create a collection of name/value pairs.

Functions#

decode_block(data)

Decode the block data from the given input if it is not None.

decode_metadata(metadata)

decode_revealed_commitment(encoded_data)

Decode the revealed commitment data from the given input if it is not None.

decode_revealed_commitment_with_hotkey(encoded_data)

Decode revealed commitment using a hotkey.

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

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

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_block(data)#

Decode the block data from the given input if it is not None.

Parameters:

data (bytes) – The block data to decode.

Returns:

The decoded block.

Return type:

int

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

metadata (bittensor.core.types.CommitmentOfResponse)

Return type:

str

bittensor.core.chain_data.utils.decode_revealed_commitment(encoded_data)#

Decode the revealed commitment data from the given input if it is not None.

Parameters:

encoded_data – A tuple containing the revealed message and the block number.

Returns:

A tuple containing the revealed block number and decoded commitment message.

Return type:

tuple[int, str]

bittensor.core.chain_data.utils.decode_revealed_commitment_with_hotkey(encoded_data)#

Decode revealed commitment using a hotkey.

Returns:

A tuple containing the hotkey (ss58 address) and a tuple of block

numbers and their corresponding revealed commitments.

Return type:

tuple[str, tuple[tuple[int, str], …]]

Parameters:

encoded_data (async_substrate_interface.sync_substrate.QueryMapResult)

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 – 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.

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

  • input_ (Union[list[int], bytes, scalecodec.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 – The SCALE encoded input data.

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

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

Returns:

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

Raises:

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

Return type:

Optional[dict]

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