Eternal Registry Storage
Eternal Storage for the KAIO Registries.
Eternal Storage
Registries make use of the eternal storage pattern to store information. This pattern allows for storing data indexed by the hash of its identifier, instead of contiguously with other data. The data type used for identifiers is bytes32, this is preferred to something like string for efficiency. The convention chosen for these identifiers is applying the keccak256 hash function to the string version of them. The majority of identifiers can be found in Constants.sol.
The Eternal Storage pattern has two main advantages:
Upgrading contracts is much simpler, since all data stored in the Eternal Registry will not be affected or cause any issues.
Variables can be added or deleted from the registry without having to change the contract. This is especially useful if old data becomes irrelevant, or if new data should be added to the registry. For example if one day a new data field needs to be filled out for all Dealers, this can be done without changing the Dealer Registry.
Implementation & Data Types
The implementation of eternal storage in KAIO is done using the EternalRegistryStorage.sol contract. This contract supports the following data types with the following functions:
Bool
_setBool()
getBool()
Uint256
_setUint()
getUint()
Address
_setAddress()
getAddress()
String
_setString()
getString()
Bytes32
_setBytes()
getBytes()
Batch (any combination of the above)*
_setBatch()
getBatch()
Address[]
_setAddressArray()
_setAddressArrayIndexValue()
_pushAddressArray()
_deleteAddressArrayIndexValue()
getAddressArray(), getAddressArrayIndexValue()
*It is possible to get and set multiple values at once using batch functions, in order to save time and gas. This includes batch getting or setting values of different types.
Last updated
