Support blake2_128Concat key hashing (#60)

This commit is contained in:
Andrew Jones
2020-01-06 13:22:57 +00:00
committed by GitHub
parent 3aa3598114
commit 80663ec6e3
+8
View File
@@ -237,6 +237,14 @@ impl<K: Encode, V: Decode + Clone> StorageMap<K, V> {
let encoded_key = key.encode();
let hash = match self.hasher {
StorageHasher::Blake2_128 => sp_core::blake2_128(&encoded_key).to_vec(),
StorageHasher::Blake2_128Concat => {
// copied from substrate Blake2_128Concat::hash since StorageHasher is not public
sp_core::blake2_128(&encoded_key)
.iter()
.chain(&encoded_key)
.cloned()
.collect::<Vec<_>>()
},
StorageHasher::Blake2_256 => sp_core::blake2_256(&encoded_key).to_vec(),
StorageHasher::Twox128 => sp_core::twox_128(&encoded_key).to_vec(),
StorageHasher::Twox256 => sp_core::twox_256(&encoded_key).to_vec(),