bittensor.utils#

Subpackages#

Submodules#

Attributes#

Exceptions#

VersionCheckError

Exception raised for errors in the version check process.

Functions#

use_torch()

Force the use of torch over numpy for certain operations.

version_checking([timeout])

Deprecated, kept for backwards compatibility. Use check_version() instead.

check_version([timeout])

Check if the current version of Bittensor is up-to-date with the latest version on PyPi.

ss58_to_vec_u8(ss58_address)

strtobool(val)

Converts a string to a boolean value.

_get_explorer_root_url_by_network_from_map(network, ...)

Returns the explorer root url for the given network name from the given network map.

get_explorer_url_for_network(network, block_hash, ...)

Returns the explorer url for the given block hash and network.

ss58_address_to_bytes(ss58_address)

Converts a ss58 address to a bytes object.

u16_normalized_float(x)

u64_normalized_float(x)

get_hash(content[, encoding])

format_error_message(error_message[, substrate])

Formats an error message from the Subtensor error information for use in extrinsics.

is_valid_ss58_address(address)

Checks if the given address is a valid ss58 address.

_is_valid_ed25519_pubkey(public_key)

Checks if the given public_key is a valid ed25519 key.

is_valid_bittensor_address_or_public_key(address)

Checks if the given address is a valid destination address.

Package Contents#

bittensor.utils.SS58_FORMAT = 42#
bittensor.utils.logging#
bittensor.utils.torch#
bittensor.utils.use_torch()[source]#

Force the use of torch over numpy for certain operations.

Return type:

bool

bittensor.utils.version_checking(timeout=15)[source]#

Deprecated, kept for backwards compatibility. Use check_version() instead.

Parameters:

timeout (int) – The timeout for calling :func:check_version function. Default is 15.

bittensor.utils.check_version(timeout=15)[source]#

Check if the current version of Bittensor is up-to-date with the latest version on PyPi. Raises a VersionCheckError if the version check fails.

Parameters:

timeout (int) – The timeout for the request to PyPI in seconds. Default is 15.

exception bittensor.utils.VersionCheckError[source]#

Bases: Exception

Exception raised for errors in the version check process.

Initialize self. See help(type(self)) for accurate signature.

bittensor.utils.RAOPERTAO = 1000000000.0#
bittensor.utils.U16_MAX = 65535#
bittensor.utils.U64_MAX = 18446744073709551615#
bittensor.utils.ss58_to_vec_u8(ss58_address)[source]#
Parameters:

ss58_address (str)

Return type:

list[int]

bittensor.utils.strtobool(val)[source]#

Converts a string to a boolean value.

truth-y values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false-y values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

Raises ValueError if ‘val’ is anything else.

Parameters:

val (str)

Return type:

Union[bool, Literal[‘==SUPRESS==’]]

bittensor.utils._get_explorer_root_url_by_network_from_map(network, network_map)[source]#

Returns the explorer root url for the given network name from the given network map.

Parameters:
  • network (str) – The network to get the explorer url for.

  • network_map (dict[str, str]) – The network map to get the explorer url from.

Returns:

The explorer url for the given network. Or None if the network is not in the network map.

Return type:

Optional[dict[str, str]]

bittensor.utils.get_explorer_url_for_network(network, block_hash, network_map)[source]#

Returns the explorer url for the given block hash and network.

Parameters:
  • network (str) – The network to get the explorer url for.

  • block_hash (str) – The block hash to get the explorer url for.

  • network_map (dict[str, dict[str, str]]) – The network maps to get the explorer urls from.

Returns:

The explorer url for the given block hash and network. Or None if the network is not known.

Return type:

Optional[dict[str, str]]

bittensor.utils.ss58_address_to_bytes(ss58_address)[source]#

Converts a ss58 address to a bytes object.

Parameters:

ss58_address (str)

Return type:

bytes

bittensor.utils.u16_normalized_float(x)[source]#
Parameters:

x (int)

Return type:

float

bittensor.utils.u64_normalized_float(x)[source]#
Parameters:

x (int)

Return type:

float

bittensor.utils.get_hash(content, encoding='utf-8')[source]#
bittensor.utils.format_error_message(error_message, substrate=None)[source]#

Formats an error message from the Subtensor error information for use in extrinsics.

Parameters:
  • error_message (dict) – A dictionary containing the error information from Subtensor.

  • substrate (SubstrateInterface, optional) – The substrate interface to use.

Returns:

A formatted error message string.

Return type:

str

bittensor.utils.is_valid_ss58_address(address)[source]#

Checks if the given address is a valid ss58 address.

Parameters:

address (str) – The address to check.

Returns:

True if the address is a valid ss58 address for Bittensor, False otherwise.

Return type:

bool

bittensor.utils._is_valid_ed25519_pubkey(public_key)[source]#

Checks if the given public_key is a valid ed25519 key.

Parameters:

public_key (Union[str, bytes]) – The public_key to check.

Returns:

True if the public_key is a valid ed25519 key, False otherwise.

Return type:

bool

bittensor.utils.is_valid_bittensor_address_or_public_key(address)[source]#

Checks if the given address is a valid destination address.

Parameters:

address (Union[str, bytes]) – The address to check.

Returns:

True if the address is a valid destination address, False otherwise.

Return type:

bool