Hi there, I am currently using an external storage pattern similar to what is described in this post, and got a few questions:
In the pattern there, all keys in mappings are hashed, for example, for an ID to Value mapping, the ID is first hashed to a bytes32 key, and
mapping(bytes32 => uint256) is used for setting, getting and deleting all
(bytes32, uint256) pairs. I am wondering if this is necessary.
I could understand in that post, a mapping for a type of values can be taken care of by only one mapping for all types of keys, be it a string or an uint256, as long as the mapped value is an uint256, the same mapping can be used. But is it really a good pattern?
What could go wrong if a plain
mapping(uint256 => uint256) is used instead? This allows more specific mappings, like
mapping(uint256 => uint256) _IDToValue;
mapping(uint256 => uint256) _BalanceToBalance, etc.
To come to a single question, is it also OK to use primitive types as keys instead of hashed values in an external storage pattern? Thanks.