-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored the work with storage #137
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instead of defining the storage trait for each data structure we have one `Storage` trait for all contracts. Simplified selection between several data storages. Removed derive macro at all. Simplified implementation of `Storage` trait. Removed module duplicating in the name. Updated storage key to be `u32`(soon new version of ink! will use it as main key instead of `[u8; 32]`). Added `OccupiedStorage` trait to allow generics in the data structures. Also it is additional guard to not occupy the same storage key. The storage key of each data structure in OpenBursh is a hash of the module path to the struct instead of hash of the string.
# Conflicts: # contracts/derive/lib.rs # contracts/src/token/psp35/extensions/batch.rs # contracts/src/token/psp35/psp35.rs
# Conflicts: # contracts/Cargo.toml # contracts/derive/Cargo.toml # contracts/derive/lib.rs # contracts/src/access/access_control/mod.rs # contracts/src/finance/payment_splitter/mod.rs # contracts/src/governance/timelock_controller/mod.rs # contracts/src/token/psp22/psp22.rs # contracts/src/token/psp34/extensions/metadata.rs # contracts/src/token/psp35/extensions/metadata.rs # contracts/src/upgradability/diamond/diamond.rs # contracts/src/upgradability/diamond/extensions/diamond_loupe.rs # docs/docs/smart-contracts/example/impls.md # example_project_structure/impls/lending/data.rs
# Conflicts: # contracts/src/token/psp35/extensions/enumerable.rs # contracts/src/token/psp35/psp35.rs
Added description of new traits. The doc will be updated in separate commit
Added general description of importing default implementation from OpenBrush. Refactored all examples to use general description to reduce boilerplate documentation. Added examples of final code into documentation. Removed `psp22::extensions::capped` because it is refactored in separate PR. Removed reentrancy guard description because it is outdated. It will be updated after trait refactoring. Updated usage of storage in all examples.
coreggon11
approved these changes
Jul 11, 2022
RustNinja
approved these changes
Jul 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One
Storage
trait for all contractsInstead of defining the storage trait for each data structure, OpenBrush provides the
openbrush::traits::Storage
trait for all contracts. Removed derive macro at all. Simplified implementation ofStorage
trait.It simplified the usage of the library:
Instead of the old version with many storage traits:
Helpers
StorageAsRef
andStorageAsMut
traitsAdded helpers
StorageAsRef
andStorageAsMut
traits. If you implement theStorage
trait those traits are implemented automatically for you. It simplified selection between several data storages in generic implementation. New versions:Old version:
OccupiedStorage
andOccupyStorage
traitsAdded the
OccupiedStorage
trait to allow generics in the data structures. Also, it is an additional guard not to occupy the same storage key. Each upgradeable data in OpenBrush implementsOccupyStorage
with provided storage key intoopenbrush::upgradeable_storage
.OccupiedStorage
is implemented by deriveStorage
macro. So if you want to use it then the data type should implementOccupyStorage
.The simplest way to not worry about it is to use
openbrush::upgradeable_storage
during the definition of your structure and useStorage
derive in the main contract.Minor improvements
Removed module duplicating in the naming of data, traits, etc.
Each main data structure is now named
Data
instead ofPSP22Data
orPSP34Data
.Each internal trait is now named
Internal
instead ofPSP22Internal
orPSP34Internal
.If you want to have several
Data
in scope or severalInternal
traits, you can use namespace to specify it:Updated storage key to be
u32
(soon, a new version of ink! will use it as the main key instead of[u8; 32]
). Provided a new macroopenbrush::storage_unique_key
that generates a storage key based on the module path to the data structure.Improved exporting of all stuff from contracts. Now when you import
openbrush::contracts::psp22::*
, it also exportspsp22
itself. So you can usepsp22::Data
orData
. Usage ofpsp22::Data
is better because it is more readable.Updated documentation. Removed common parts of each example documentation into the
Overview
section. Renamed storage of examples intoContract
.