Expose storage_prefix logic, and remove duplicate code (#9621)

* expose storage prefix generation, remove duplicate code

* remove more duplicate code

* clean up import

* fix io test

* remove slicing

* Update frame/support/src/storage/mod.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Shawn Tabrizi
2021-08-25 15:16:47 -04:00
committed by GitHub
parent 531fd70e22
commit 7c3890c652
12 changed files with 89 additions and 191 deletions
+1 -8
View File
@@ -30,14 +30,7 @@ impl<T: GetStorageVersion + PalletInfoAccess> PalletVersionToStorageVersionHelpe
const PALLET_VERSION_STORAGE_KEY_POSTFIX: &[u8] = b":__PALLET_VERSION__:";
fn pallet_version_key(name: &str) -> [u8; 32] {
let pallet_name = sp_io::hashing::twox_128(name.as_bytes());
let postfix = sp_io::hashing::twox_128(PALLET_VERSION_STORAGE_KEY_POSTFIX);
let mut final_key = [0u8; 32];
final_key[..16].copy_from_slice(&pallet_name);
final_key[16..].copy_from_slice(&postfix);
final_key
crate::storage::storage_prefix(name.as_bytes(), PALLET_VERSION_STORAGE_KEY_POSTFIX)
}
sp_io::storage::clear(&pallet_version_key(<T as PalletInfoAccess>::name()));