Handle StorageEntry empty keys (#565)

* Handle `StorageEntry` empty keys

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update `polkadot.rs`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-06-16 16:35:34 +03:00
committed by GitHub
parent 8bceda2b39
commit 7621d71892
2 changed files with 12946 additions and 10178 deletions
+15 -7
View File
@@ -166,13 +166,21 @@ fn generate_storage_entry_fns(
None => quote!(#t),
}
});
let entry_struct = quote! {
pub struct #entry_struct_ident <'a>( #( pub &'a #field_types ),* );
// There cannot be a reference without a parameter.
let should_ref = !fields.is_empty();
let (entry_struct, constructor) = if should_ref {
(
quote! {
pub struct #entry_struct_ident <'a>( #( pub &'a #field_types ),* );
},
quote!( #entry_struct_ident( #( #field_names ),* ) ),
)
} else {
(
quote!( pub struct #entry_struct_ident; ),
quote!( #entry_struct_ident ),
)
};
let constructor =
quote!( #entry_struct_ident( #( #field_names ),* ) );
let key_impl = if hashers.len() == fields.len() {
// If the number of hashers matches the number of fields, we're dealing with
@@ -214,7 +222,7 @@ fn generate_storage_entry_fns(
)
};
(fields, entry_struct, constructor, key_impl, true)
(fields, entry_struct, constructor, key_impl, should_ref)
}
_ => {
let (lifetime_param, lifetime_ref) = (quote!(<'a>), quote!(&'a));