-
Notifications
You must be signed in to change notification settings - Fork 482
Fallible storage get and set methods for Lazy and Mapping
#1910
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
Conversation
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
get and set methods for Lazy get and set methods for Lazy and Mapping
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
xgreenx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and clean to me=)
Signed-off-by: Cyrill Leutwiler <[email protected]>
ced6ba3 to
a2c991b
Compare
Signed-off-by: Cyrill Leutwiler <[email protected]>
🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑These are the results when building the
Link to the run | Last update: Fri Oct 27 13:13:23 CEST 2023 |
ascjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'd like to see the try_ methods exercised in the mapping-integration-tests e2e tests though.
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
ascjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (needs merge conflict fixing)
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Adds
try_*methods for reading and writingLazyandMappingvalues to and from storage (forMapping, the encoded size of the key is also accounted for).Fallible writes are implemented by extending the
Storabletrait withencoded_sizemethod (which provides a default implementation using the SCALE version method ofencoded_size). There is alsosize_hintin SCALE but I think we want an exact number and not an estimate. This will encode the stored value twice (the first time it's thrown away; no allocation happening), however users can optimize it by overwriting theencoded_sizemethod to return a constant instead if possible and required.Fallible reads are implemented using the
contains_storage_keyAPI, which will tell the size. This implies two calls to the contracts pallet (one to get the size and one to read the value). This can be improved by adding a correspondingReturnCodeto the contracts pallet, which can then be used by theget_storageAPI method. But for now, the two subsequent calls are necessary.