bittensor.utils.balance#
Classes#
Represents the bittensor balance of the wallet, stored as rao (int). |
|
Represents a fixed point |
Functions#
|
Validate that the provided value is a Balance instance. |
|
Converts a fixed-point value (e.g., U64F64) into a floating-point number. |
|
Helper function to create a Balance object from an int (Rao) |
|
Helper function to create a Balance object from a float (Tao) |
Module Contents#
- class bittensor.utils.balance.Balance(balance)[source]#
Represents the bittensor balance of the wallet, stored as rao (int).
This class provides a way to interact with balances in two different units: rao and tao. It provides methods to convert between these units, as well as to perform arithmetic and comparison operations.
- Variables:
- Parameters:
Note
To ensure arithmetic operations between Balance instances work correctly, they must set the same unit for each using the netuid.
Examples
balance_wallet_default = Balance.from_tao(10, netuid=14) balance_wallet_secret = Balance.from_tao(2, netuid=14) total_balance = balance_wallet_default + balance_wallet_secret
# or
balance_wallet_default = Balance.from_tao(10).set_unit(netuid=14) balance_wallet_secret = Balance.from_tao(2).set_unit(netuid=14) total_balance = balance_wallet_default + balance_wallet_secret
The from_tao() and from_rao() methods accept the netuid parameter to set the appropriate unit symbol.
Note
When performing arithmetic or comparison operations where the first operand is a Balance instance and the second operand is not, the second operand is implicitly interpreted as a raw amount in rao, using the same unit (netuid) as the first operand. This allows interoperability with integer or float values, but may result in unexpected behavior if the caller assumes the second operand is in tao.
Example
balance = Balance.from_tao(10, netuid=14) result = balance + 5000 # 5 will be treated as 5000 rao, not 5 tao print(result) output: τ10.000005000
Initialize a Balance object. If balance is an int, it’s assumed to be in rao. If balance is a float, it’s assumed to be in tao.
- static from_float(amount, netuid=0)[source]#
Given tao, return
Balance()object with rao(int) and tao(float), where rao = int(tao*pow(10,9))
- static from_rao(amount, netuid=0)[source]#
Given rao, return Balance object with rao(
int) and tao(float), where rao = int(tao*pow(10,9))
- static from_tao(amount, netuid=0)[source]#
Given tao, return Balance object with rao(
int) and tao(float), where rao = int(tao*pow(10,9))
- property tao#
- class bittensor.utils.balance.FixedPoint[source]#
Bases:
TypedDictRepresents a fixed point
U64F64number. Wherebitsis a U128 representation of the fixed point number.This matches the type of the Alpha shares.
Initialize self. See help(type(self)) for accurate signature.
- bittensor.utils.balance.check_balance_amount(amount, allow_none=True)#
Validate that the provided value is a Balance instance.
This function ensures that the amount argument is a Balance object. If a non-Balance type is passed, it raises a BalanceTypeError to enforce consistent usage of Balance objects across arithmetic operations.
- Parameters:
- Returns:
Always returns None if validation passes.
- Return type:
None
- Raises:
BalanceTypeError – If amount is not a Balance instance and not None.
- bittensor.utils.balance.fixed_to_float(fixed, frac_bits=64, total_bits=128)[source]#
Converts a fixed-point value (e.g., U64F64) into a floating-point number.
- Parameters:
fixed (Union[FixedPoint, scalecodec.ScaleType])
frac_bits (int)
total_bits (int)
- Return type: