This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
decl_storage: storage the key alongside the value to be able to iterate on key/value #4362
Labels
J0-enhancement
An additional feature request.
Milestone
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 justvalue
.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:
(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.
(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)
(value, key)
and just decode the value, thus there won't be any optimisation anymore, it will be same as usingmutate
.StorageMap::swap: we can't swap the raw data anymore, solutions:
(key, value)
then we have to decode the key only and then we can swap split and swap the raw values(value, key)
we have to decode the value and then we can split and swap the raw value(value, key, key_length)
then we decode key_length and then we can split and swap the raw value.The text was updated successfully, but these errors were encountered: