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.
Inspired by #557 but also a long struggle with the Bucket and ReadOnlyBucket types.
We can make the Bucket always immutable, just by storing the access/mapping info there. And then pass in
&Storage
or&mut Storage
everywhere. We can useBucket
or&Bucket
everywhere, also in queries, and the compiler will automatically prevent use from calling the mutable functions if we only have immutable storage.This also let's us have 2 buckets open at once without worrying about lifetimes.
The downside is one more argument to each call. However, as the typical usage is more or less:
let acct = tokens(&deps.storage).load(&sender_raw)?
we just transmute that to:
let acct = tokens().load(&deps.storage, &sender_raw)?
tokens
(the bucket constructor with type and namespace info) need no more arguments, and could theoretically be a const (created compile time) if we migrate fromVec<u8>
to&'a [u8]
for namespace storage, which I have done in #557, making these even shorter to write and faster to run.You can look at a202e4d to see what it took to migrate a moderate contract to the new form (not much).