This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Description
as follow up of #4185 (comment)
It would be interesting to introduce a way in decl_storage to tell to store the key alongside the value.
at the end the storage will have the data: (value, key).
This way when iterating on prefix we could actually iterate on (key, value) instead of just value.
This could be just a new attribute.
Implementing the StorageMap and other trait is not straightforward, here are some difficultyies:
-
StorageMap::append is implementing to work on the raw not decoded value. If the raw value is (value, key) we can't call scale_codec::EncodeAppend::append on it because we need to give only the raw data for the value.
multiple solution here:
- store actually
(key, value), decode the key, the remaining byte are the raw value.
not very good because get function will also have to decode the key.
- store
(value, key, key_length), so we can use key_length to split the raw data.
(key_length is encoded on 4 byte or in a compact encoding but reversed so we can decode from the end)
- implement a new EncodeAppendPreserving which does append on a raw data while preserving the suffix.
- store
(value, key) and just decode the value, thus there won't be any optimisation anymore, it will be same as using mutate.
-
StorageMap::swap: we can't swap the raw data anymore, solutions:
- if we store
(key, value) then we have to decode the key only and then we can swap split and swap the raw values
- if we store
(value, key) we have to decode the value and then we can split and swap the raw value
- if we store
(value, key, key_length) then we decode key_length and then we can split and swap the raw value.