Portal is designed to host multiple parties without them affecting each other's storage space under any condition.
DataStoreUtils Library
DataStore is a storage management tool designed to create a safe and scalable storage layout with the help of IDs and KEYs.
Creating a sustainable development environment, even in ever changing technology.
With DataStore, Portal achieves 3 goals:
A Dynamic Struct that is defined with the "TYPE" parameter, that can hold any amount of parameters, instead of only 16 (max # of variables a struct can hold in Solidity).
Make it very easy to build new classes that have different parameters and functionalities, without altering the codebase.
Separating the storage space of the contract, allowing Portal to maintain multiple parties without any friction.
Ensuring the variable types: uint, address, and bytes.
Deep Dive
Storage Management library for dynamic structs based on data types.
Keys are bound to IDs, ensuring 2 IDs with same parameters can not share a storage slot.
TYPEs are explicit, 4 representing Operators, 5 representing pools, and so on...
NAMEs should be guarded within the same TYPE, meaning there can only be 1 entity with a given NAME and TYPE.
Sample Write Operation
DataStoreLib.sol
functionwriteUintForId(DataStorestorage self,uint256_id,bytes32_key,uint256 data ) public { self.UintData[keccak256(abi.encodePacked(_id, _key))] = data; }
Basically, it takes the id and key pair encoded, secures a slot in the mapping for the id & key pair, and assigns the data to slot in the UintData mapping where the DataStore struct is taken as a storage argument. Every write operation in the library follows the same procedure.
This is also a typical read operation in the library, getting the data from the assigned slot with the given id and key pair, and returning the data publicly with the view restriction.
Reading the DataStore Through Portal
Portal has a public endpoint for the view functions of the DataStore.
This provides access to all data stored in the Portal, without needing to go through the docs, and scan through all the functions 🙂
Portal.sol
functiongenerateId(stringcalldata_name,uint256_type ) externalpurevirtualoverridereturns (uint256 id) { id =uint256(keccak256(abi.encodePacked(_name, _type))); }
generateId() Mimics the DataStore.generateId for string inputs.