bittensor.utils#
Subpackages#
Submodules#
Attributes#
Exceptions#
Exception raised for errors in the version check process. |
Functions#
|
Returns the explorer root url for the given network name from the given network map. |
|
Checks if the given public_key is a valid ed25519 key. |
|
Check if the current version of Bittensor is up-to-date with the latest version on PyPi. |
|
Decodes hex-encoded strings in a dictionary. |
|
Formats an error message from the Subtensor error information for use in extrinsics. |
|
Returns the explorer url for the given block hash and network. |
|
|
|
Converts a hex-encoded string into bytes. Handles 0x-prefixed and non-prefixed hex-encoded strings. |
Checks if the given address is a valid destination address. |
|
|
Checks if the given address is a valid ss58 address. |
|
Converts a ss58 address to a bytes object. |
|
|
|
Converts a string to a boolean value. |
|
Attempts to decrypt a wallet's coldkey or hotkey |
Force the use of torch over numpy for certain operations. |
|
|
Validates if the provided endpoint URL is a valid WebSocket URL. |
|
Deprecated, kept for backwards compatibility. Use check_version() instead. |
Package Contents#
- bittensor.utils.Certificate#
- bittensor.utils.RAOPERTAO = 1000000000.0#
- bittensor.utils.SS58_FORMAT = 42#
- bittensor.utils.U16_MAX = 65535#
- bittensor.utils.U64_MAX = 18446744073709551615#
- bittensor.utils.UnlockStatus#
- 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._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.
- bittensor.utils._is_valid_ed25519_pubkey(public_key)[source]#
Checks if the given public_key is a valid ed25519 key.
- 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
.
- bittensor.utils.decode_hex_identity_dict(info_dictionary)#
Decodes hex-encoded strings in a dictionary.
This function traverses the given dictionary, identifies hex-encoded strings, and decodes them into readable strings. It handles nested dictionaries and lists within the dictionary.
- Parameters:
info_dictionary (dict) – The dictionary containing hex-encoded strings to decode.
- Returns:
The dictionary with decoded strings.
- Return type:
Examples
input_dict = { … “name”: {“value”: “0x6a6f686e”}, … “additional”: [ … [{“data”: “0x64617461”}] … ] … } decode_hex_identity_dict(input_dict) {‘name’: ‘john’, ‘additional’: [(‘data’, ‘data’)]}
- bittensor.utils.format_error_message(error_message)[source]#
Formats an error message from the Subtensor error information for use in extrinsics.
- 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:
- Returns:
The explorer url for the given block hash and network. Or None if the network is not known.
- Return type:
- bittensor.utils.hex_to_bytes(hex_str)#
Converts a hex-encoded string into bytes. Handles 0x-prefixed and non-prefixed hex-encoded strings.
- bittensor.utils.is_valid_bittensor_address_or_public_key(address)[source]#
Checks if the given address is a valid destination address.
- bittensor.utils.is_valid_ss58_address(address)[source]#
Checks if the given address is a valid ss58 address.
- bittensor.utils.logging#
- bittensor.utils.ss58_address_to_bytes(ss58_address)[source]#
Converts a ss58 address to a bytes object.
- 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.
- bittensor.utils.torch#
- bittensor.utils.unlock_key(wallet, unlock_type='coldkey')#
Attempts to decrypt a wallet’s coldkey or hotkey :param wallet: a Wallet object :param unlock_type: the key type, ‘coldkey’ or ‘hotkey’
Returns: UnlockStatus for success status of unlock, with error message if unsuccessful
- Parameters:
wallet (bittensor_wallet.Wallet)
- Return type:
UnlockStatus
- bittensor.utils.use_torch()[source]#
Force the use of torch over numpy for certain operations.
- Return type:
- bittensor.utils.validate_chain_endpoint(endpoint_url)#
Validates if the provided endpoint URL is a valid WebSocket URL.