New storage Api, StorageMap which accepts 2 optional keys

I am bringing this topic as I had a thought and I was working on my project and asked myself what if the storage item could accepts 2 keys ( not StorageDoubleMap) but take it as if one of the predefined keys is provided , we can then get access of the stored value.

So my questions are:

  1. I know I can implement this but any security issues concerning this?
  2. I think the caveat is I need to pre-define the keys at storage initialization right?
  3. Any feedback on this thought and do you guys think this will be an add up or not something useful at all?
1 Like

I guess I’m not really seeing the difference from a StorageDoubleMap or a StorageMap with a tuple key, do you mind giving a code snippet example of what you mean?

So for example it will be like this

type Example = StorageOrMap<_,hasher, key1,key2,value>;

Now when setting the value
Example::insert(key1, key2, value);

But when accessing the value
Example::get(key1 or key2);

So its like you have k = 2, total number of keys but you only need n=1 key from k space to access the value.

I ran into this as well - might I suggest perhaps hashing together the two IDs, or coming up with some unique identifier then just using StorageMap?

Could prove useful meanwhile.

Since storage keys are identified by their hash, going from left to right, you can easily get the values that share the same key 1, but I don’t think there’s a reasonable way of using either key 1 or key 2. I also can’t seem to think of a good use case for it, as you could simply use a K->V map and store both keys pointing to the same value.

So what I was thinking is 2 keys point to a single value. But yeah now I think there will be a problem of data races