🔐Isolated Storage
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.
The DataStore Struct
Within the struct, there are 4 different mappings to serve different types of storage.
Generating an ID and Key
IDs should be unique.
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
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.
Sample Read Operation
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 🙂
generateId() Mimics the DataStore.generateId for string inputs.
An example key generation can be:
Reading Simple Data
An example read operation:
---
Reading an array
Currently only arrays are:
validators
andinterfaces
Getting length of an array:
An example read operation on arrays:
---
Last updated