Skip to content

Commit

Permalink
Change StorageEntryType keys/values to types instead of strings (#8)
Browse files Browse the repository at this point in the history
* Change StorageEntryType keys/values to types instead of strings

* Change storage to a single object not a Vec

* Fix IntoPortable impl
  • Loading branch information
ascjones authored Apr 13, 2021
1 parent be8092d commit 86bf2b3
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions frame-metadata/src/v13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl IntoPortable for SignedExtensionMetadata {
)]
pub struct ModuleMetadata<T: Form = MetaForm> {
pub name: T::String,
pub storage: Option<Vec<StorageMetadata<T>>>,
pub storage: Option<StorageMetadata<T>>,
pub calls: Option<Vec<FunctionMetadata<T>>>,
pub event: Option<Vec<EventMetadata<T>>>,
pub constants: Option<Vec<ModuleConstantMetadata<T>>>,
Expand All @@ -147,9 +147,7 @@ impl IntoPortable for ModuleMetadata {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ModuleMetadata {
name: self.name.into_portable(registry),
storage: self
.storage
.map(|storage| registry.map_into_portable(storage)),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| registry.map_into_portable(calls)),
event: self.event.map(|event| registry.map_into_portable(event)),
constants: self
Expand Down Expand Up @@ -243,19 +241,19 @@ pub enum StorageHasher {
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
)]
pub enum StorageEntryType<T: Form = MetaForm> {
Plain(T::String),
Plain(T::Type),
Map {
hasher: StorageHasher,
key: T::String,
value: T::String,
key: T::Type,
value: T::Type,
// is_linked flag previously, unused now to keep backwards compat
unused: bool,
},
DoubleMap {
hasher: StorageHasher,
key1: T::String,
key2: T::String,
value: T::String,
key1: T::Type,
key2: T::Type,
value: T::Type,
key2_hasher: StorageHasher,
},
}
Expand All @@ -265,16 +263,16 @@ impl IntoPortable for StorageEntryType {

fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::Plain(plain) => StorageEntryType::Plain(plain.into_portable(registry)),
Self::Plain(plain) => StorageEntryType::Plain(registry.register_type(&plain)),
Self::Map {
hasher,
key,
value,
unused,
} => StorageEntryType::Map {
hasher,
key: key.into_portable(registry),
value: value.into_portable(registry),
key: registry.register_type(&key),
value: registry.register_type(&value),
unused,
},
Self::DoubleMap {
Expand All @@ -285,9 +283,9 @@ impl IntoPortable for StorageEntryType {
key2_hasher,
} => StorageEntryType::DoubleMap {
hasher,
key1: key1.into_portable(registry),
key2: key2.into_portable(registry),
value: value.into_portable(registry),
key1: registry.register_type(&key1),
key2: registry.register_type(&key2),
value: registry.register_type(&value),
key2_hasher,
},
}
Expand Down

0 comments on commit 86bf2b3

Please sign in to comment.