Methods

These are the operations that can be performed on the StateManager contract.

Read Functions

function size() external view returns (uint256);

Retrieves the size (length) of the State Manager database.

function all() external view returns (StateEntry[] memory);

Returns an array that contains a StateEntry struct for each variable saved in the State Manager.

function partialList(uint256 start, uint256 offset) external view returns (StateEntry[] memory);

Pass a range position (start and offset) in this function for it to return an array that contains a StateEntry struct for each variable of the range.

function list(string[] calldata keys) external view returns (StateEntry[] memory);

Pass an array of keys in this function for it to return an array that contains a StateEntry struct for each variable that corresponds to a key.

function listByIndices(uint256[] calldata indices) external view returns (StateEntry[] memory);

Pass an array of indices in this function for it to return an array that contains a StateEntry struct for each variable that corresponds to a key.

An index is a uint256 representing a specific key. This information is saved in the _index mapping in the StateManager.

function exists(string calldata key) external view returns(bool result, uint256 index);

Pass a key in this function for it to retrieve:

  1. If that key exists in the StateManager (true) or not (false).

  2. The key's index.

function get(string calldata key) external view returns(StateEntry memory);

Pass a key in this function for it to return the StateEntry struct that corresponds to the key.

function getByIndex(uint256 index) external view returns(StateEntry memory);

Pass an index in this function for it to returns the StateEntry struct that corresponds to that index.

Write Functions

function set(StateEntry calldata newValue) external returns(bytes memory replacedValue);

Pass a StateEntry struct in this function for it to add a new variable to the StateManager.

If the key passed in the struct corresponds to a variable that already exists in the StateManager, it is replaced with the new value. In this case, the function returns the replaced value.

function batchSet(StateEntry[] calldata newValues) external returns(bytes[] memory replacedValues);

Pass multiple StateEntry structs in this function for it to add new variables to the StateManager.

If the keys passed in the structs correspond to variables that already exist in the StateManager, they are replaced with the new values. In this case, the function returns the replaced values.

function remove(string calldata key) external returns(bytes32 removedType, bytes memory removedValue);

Pass a key in this function for it to remove the corresponding variable from the StateManager.

The function returns the removed variable's type (bool, int, uint, string, etc..) and its value.

function batchRemove(string[] calldata keys) external returns(bytes32[] memory removedTypes, bytes[] memory removedValues);

Pass multiple keys in this function to remove the corresponding variables from the StateManager.

The function returns the removed variables' types (bool, int, uint, string, etc..) and values.

function removeByIndices(uint256[] calldata indices) external returns(bytes32[] memory removedTypes, bytes[] memory removedValues);

Pass multiple indices in this function to remove the corresponding variables from the StateManager

The output function returns the removed variables' types (bool, int, uint, string etc...) and values.

Note

To avoid side effects or undesired transaction reverts, the array of indices must be passed by force in descending order. For example: If you want to delete the variables at indexes 9, 18 and 13, pass the array ordered as [18, 13, 9]. This will ensure the function behavior is respected correctly.

Last updated