bittensor.core.chain_data.utils#

Chain data helper functions and data.

Attributes#

Classes#

ChainDataType

Create a collection of name/value pairs.

Functions#

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.

decode_account_id(account_id_bytes)

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

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(*args, **kwds)[source]#

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.

NeuronInfo = 1#
SubnetInfo = 2#
DelegateInfo = 3#
NeuronInfoLite = 4#
DelegatedInfo = 5#
StakeInfo = 6#
IPInfo = 7#
SubnetHyperparameters = 8#
ScheduledColdkeySwapInfo = 9#
AccountId = 10#
bittensor.core.chain_data.utils.from_scale_encoding(input_, type_name, is_vec=False, is_option=False)[source]#

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)[source]#

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.custom_rpc_type_registry#
bittensor.core.chain_data.utils.decode_account_id(account_id_bytes)[source]#

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.process_stake_data(stake_data)[source]#

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