Change StorageEntryType keys/values to types instead of strings (#8)

* Change StorageEntryType keys/values to types instead of strings

* Change storage to a single object not a Vec

* Fix IntoPortable impl
This commit is contained in:
Andrew Jones
2021-04-13 09:56:34 +01:00
committed by GitHub
parent be8092d7bf
commit 86bf2b374c
+14 -16
View File
@@ -131,7 +131,7 @@ impl IntoPortable for SignedExtensionMetadata {
)] )]
pub struct ModuleMetadata<T: Form = MetaForm> { pub struct ModuleMetadata<T: Form = MetaForm> {
pub name: T::String, pub name: T::String,
pub storage: Option<Vec<StorageMetadata<T>>>, pub storage: Option<StorageMetadata<T>>,
pub calls: Option<Vec<FunctionMetadata<T>>>, pub calls: Option<Vec<FunctionMetadata<T>>>,
pub event: Option<Vec<EventMetadata<T>>>, pub event: Option<Vec<EventMetadata<T>>>,
pub constants: Option<Vec<ModuleConstantMetadata<T>>>, pub constants: Option<Vec<ModuleConstantMetadata<T>>>,
@@ -147,9 +147,7 @@ impl IntoPortable for ModuleMetadata {
fn into_portable(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
ModuleMetadata { ModuleMetadata {
name: self.name.into_portable(registry), name: self.name.into_portable(registry),
storage: self storage: self.storage.map(|storage| storage.into_portable(registry)),
.storage
.map(|storage| registry.map_into_portable(storage)),
calls: self.calls.map(|calls| registry.map_into_portable(calls)), calls: self.calls.map(|calls| registry.map_into_portable(calls)),
event: self.event.map(|event| registry.map_into_portable(event)), event: self.event.map(|event| registry.map_into_portable(event)),
constants: self constants: self
@@ -243,19 +241,19 @@ pub enum StorageHasher {
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
)] )]
pub enum StorageEntryType<T: Form = MetaForm> { pub enum StorageEntryType<T: Form = MetaForm> {
Plain(T::String), Plain(T::Type),
Map { Map {
hasher: StorageHasher, hasher: StorageHasher,
key: T::String, key: T::Type,
value: T::String, value: T::Type,
// is_linked flag previously, unused now to keep backwards compat // is_linked flag previously, unused now to keep backwards compat
unused: bool, unused: bool,
}, },
DoubleMap { DoubleMap {
hasher: StorageHasher, hasher: StorageHasher,
key1: T::String, key1: T::Type,
key2: T::String, key2: T::Type,
value: T::String, value: T::Type,
key2_hasher: StorageHasher, key2_hasher: StorageHasher,
}, },
} }
@@ -265,7 +263,7 @@ impl IntoPortable for StorageEntryType {
fn into_portable(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self { match self {
Self::Plain(plain) => StorageEntryType::Plain(plain.into_portable(registry)), Self::Plain(plain) => StorageEntryType::Plain(registry.register_type(&plain)),
Self::Map { Self::Map {
hasher, hasher,
key, key,
@@ -273,8 +271,8 @@ impl IntoPortable for StorageEntryType {
unused, unused,
} => StorageEntryType::Map { } => StorageEntryType::Map {
hasher, hasher,
key: key.into_portable(registry), key: registry.register_type(&key),
value: value.into_portable(registry), value: registry.register_type(&value),
unused, unused,
}, },
Self::DoubleMap { Self::DoubleMap {
@@ -285,9 +283,9 @@ impl IntoPortable for StorageEntryType {
key2_hasher, key2_hasher,
} => StorageEntryType::DoubleMap { } => StorageEntryType::DoubleMap {
hasher, hasher,
key1: key1.into_portable(registry), key1: registry.register_type(&key1),
key2: key2.into_portable(registry), key2: registry.register_type(&key2),
value: value.into_portable(registry), value: registry.register_type(&value),
key2_hasher, key2_hasher,
}, },
} }