bittensor.chain_data#
This module provides data structures and functions for working with the Bittensor network, including neuron and subnet information, SCALE encoding/decoding, and custom RPC type registry.
Attributes#
Classes#
Create a collection of name/value pairs. |
|
Dataclass for neuron metadata. |
|
Dataclass for neuron metadata, but without the weights and bonds. |
|
Dataclass for prometheus info. |
|
Dataclass for DelegateLiteInfo. This is a lighter version of |
|
Dataclass for delegate information. For a lighter version of this class, see |
|
Dataclass for stake info. |
|
Dataclass for subnet info. |
|
Dataclass for subnet hyperparameters. |
|
Dataclass for associated IP Info. |
|
dict() -> new empty dictionary |
|
Dataclass for scheduled coldkey swap information. |
Functions#
|
Decodes input_ data from SCALE encoding based on the specified type name and modifiers. |
|
Module Contents#
- bittensor.chain_data.custom_rpc_type_registry#
- class bittensor.chain_data.AxonInfo[source]#
-
- to_string()[source]#
Converts the AxonInfo object to a string representation using JSON.
- Return type:
- classmethod from_string(json_string)[source]#
Creates an AxonInfo object from its string representation using JSON.
- Parameters:
json_string (str) – The JSON string representation of the AxonInfo object.
- Returns:
An instance of AxonInfo created from the JSON string. If decoding fails, returns a default AxonInfo object with default values.
- Return type:
- Raises:
json.JSONDecodeError – If there is an error in decoding the JSON string.
TypeError – If there is a type error when creating the AxonInfo object.
ValueError – If there is a value error when creating the AxonInfo object.
- class bittensor.chain_data.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#
- bittensor.chain_data.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, optional) – Whether the data is a vector of the specified type. Default is
False
.is_option (bool, optional) – 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]
- class bittensor.chain_data.NeuronInfo[source]#
Dataclass for neuron metadata.
- stake_dict: Dict[str, bittensor.utils.balance.Balance]#
- total_stake: bittensor.utils.balance.Balance#
- prometheus_info: PrometheusInfo | None = None#
- classmethod fix_decoded_values(neuron_info_decoded)[source]#
Fixes the values of the NeuronInfo object.
- Parameters:
neuron_info_decoded (Any)
- Return type:
- classmethod from_vec_u8(vec_u8)[source]#
Returns a NeuronInfo object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of NeuronInfo objects from a
vec_u8
- Parameters:
vec_u8 (List[int])
- Return type:
List[NeuronInfo]
- class bittensor.chain_data.NeuronInfoLite[source]#
Dataclass for neuron metadata, but without the weights and bonds.
- stake_dict: Dict[str, bittensor.utils.balance.Balance]#
- total_stake: bittensor.utils.balance.Balance#
- prometheus_info: PrometheusInfo | None#
- axon_info: NeuronInfoLite.axon_info#
- classmethod fix_decoded_values(neuron_info_decoded)[source]#
Fixes the values of the NeuronInfoLite object.
- Parameters:
neuron_info_decoded (Any)
- Return type:
- classmethod from_vec_u8(vec_u8)[source]#
Returns a NeuronInfoLite object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of NeuronInfoLite objects from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
List[NeuronInfoLite]
- class bittensor.chain_data.PrometheusInfo[source]#
Dataclass for prometheus info.
- class bittensor.chain_data.DelegateInfoLite[source]#
Dataclass for DelegateLiteInfo. This is a lighter version of
DelegateInfo()
.- Parameters:
delegate_ss58 (str) – Hotkey of the delegate for which the information is being fetched.
take (float) – Take of the delegate as a percentage.
nominators (int) – Count of the nominators of the delegate.
owner_ss58 (str) – Coldkey of the owner.
registrations (list[int]) – List of subnets that the delegate is registered on.
validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.
return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.
total_daily_return (int) – Total daily return of the delegate.
- class bittensor.chain_data.DelegateInfo[source]#
Dataclass for delegate information. For a lighter version of this class, see
DelegateInfoLite()
.- Parameters:
hotkey_ss58 (str) – Hotkey of the delegate for which the information is being fetched.
total_stake (int) – Total stake of the delegate.
nominators (list[Tuple[str, int]]) – List of nominators of the delegate and their stake.
take (float) – Take of the delegate as a percentage.
owner_ss58 (str) – Coldkey of the owner.
registrations (list[int]) – List of subnets that the delegate is registered on.
validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.
return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.
total_daily_return (int) – Total daily return of the delegate.
- total_stake: bittensor.utils.balance.Balance#
- nominators: List[Tuple[str, bittensor.utils.balance.Balance]]#
- return_per_1000: bittensor.utils.balance.Balance#
- total_daily_return: bittensor.utils.balance.Balance#
- classmethod fix_decoded_values(decoded)[source]#
Fixes the decoded values.
- Parameters:
decoded (Any)
- Return type:
- classmethod from_vec_u8(vec_u8)[source]#
Returns a DelegateInfo object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
Optional[DelegateInfo]
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of DelegateInfo objects from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
List[DelegateInfo]
- classmethod delegated_list_from_vec_u8(vec_u8)[source]#
Returns a list of Tuples of DelegateInfo objects, and Balance, from a
vec_u8
.This is the list of delegates that the user has delegated to, and the amount of stake delegated.
- Parameters:
vec_u8 (List[int])
- Return type:
List[Tuple[DelegateInfo, bittensor.utils.balance.Balance]]
- class bittensor.chain_data.StakeInfo[source]#
Dataclass for stake info.
- classmethod fix_decoded_values(decoded)[source]#
Fixes the decoded values.
- Parameters:
decoded (Any)
- Return type:
- class bittensor.chain_data.SubnetInfo[source]#
Dataclass for subnet info.
- classmethod from_vec_u8(vec_u8)[source]#
Returns a SubnetInfo object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
Optional[SubnetInfo]
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of SubnetInfo objects from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
List[SubnetInfo]
- classmethod fix_decoded_values(decoded)[source]#
Returns a SubnetInfo object from a decoded SubnetInfo dictionary.
- Parameters:
decoded (Dict)
- Return type:
- class bittensor.chain_data.SubnetHyperparameters[source]#
Dataclass for subnet hyperparameters.
- classmethod from_vec_u8(vec_u8)[source]#
Returns a SubnetHyperparameters object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
Optional[SubnetHyperparameters]
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of SubnetHyperparameters objects from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
List[SubnetHyperparameters]
- classmethod fix_decoded_values(decoded)[source]#
Returns a SubnetInfo object from a decoded SubnetInfo dictionary.
- Parameters:
decoded (Dict)
- Return type:
- class bittensor.chain_data.IPInfo[source]#
Dataclass for associated IP Info.
- encode()[source]#
Returns a dictionary of the IPInfo object that can be encoded.
- Return type:
Dict[str, Any]
- classmethod fix_decoded_values(decoded)[source]#
Returns a SubnetInfo object from a decoded IPInfo dictionary.
- Parameters:
decoded (Dict)
- Return type:
- class bittensor.chain_data.ProposalVoteData[source]#
Bases:
TypedDict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.
- bittensor.chain_data.ProposalCallData#
- class bittensor.chain_data.ScheduledColdkeySwapInfo[source]#
Dataclass for scheduled coldkey swap information.
- classmethod fix_decoded_values(decoded)[source]#
Fixes the decoded values.
- Parameters:
decoded (Any)
- Return type:
- classmethod from_vec_u8(vec_u8)[source]#
Returns a ScheduledColdkeySwapInfo object from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
Optional[ScheduledColdkeySwapInfo]
- classmethod list_from_vec_u8(vec_u8)[source]#
Returns a list of ScheduledColdkeySwapInfo objects from a
vec_u8
.- Parameters:
vec_u8 (List[int])
- Return type:
List[ScheduledColdkeySwapInfo]