# [Ride v4 and v3] Data Weight
⚠️ This is the documentation for the Standard library version 4 and 3. We recommend to use version 6. Go to version 6
The weight of each value approximately corresponds to its size in bytes. Weight is used in limitations on creating and comparing values.
# Weight Calculation
Data type | Weight of value |
---|---|
Boolean | 1 |
ByteVector | Size in bytes |
Int | 8 |
List | See Weight of List |
String | Size in bytes |
Structure | See Weight of Tuple or Structure |
Tuple | See Weight of Tuple or Structure |
Unit | 40 |
# Weight of List
The weight of the list is calculated as follows:
Wlist = 20 + 20 × Q + Welems
where:
- Q is a number of elements.
- Welems is a total weight of elements.
# Weight of Tuple or Structure
The weight of the tuple or structure is calculated as follows:
Wstruct = 40 + 30 × Q + Wfields
where:
- Q is a number of fields.
- Wfields is a total weight of fields.
# Example
Let's consider the AssetPair structure:
AssetPair(amountAsset: ByteVector|Unit, priceAsset: ByteVector|Unit)
An asset ID is a ByteVector
of 32 bytes, its weight is 32. If both assets in the pair are not WAVES, then the weight of the AssetPair
structure is:
WAssetPair = 40 + 30 × 2 + (32 + 32) = 164
If one of the assets is WAVES, then the corresponding field is of type Unit
and its weight is 40. Then the weight of the AssetPair
structure is:
WAssetPair = 40 + 30 × 2 + (32 + 40) = 172
# Limitations
- The maximum weight of the value is 307200.
- A comparison of values is not allowed if the weight of each value exceeds 13000.
If the limitations are exceeded, the script fails.