Skip to content

Commit

Permalink
Handle StorageEntry empty keys (#565)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lexnv authored Jun 16, 2022
1 parent 8bceda2 commit 7621d71
Show file tree
Hide file tree
Showing 2 changed files with 12,866 additions and 10,098 deletions.
22 changes: 15 additions & 7 deletions codegen/src/api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 7621d71

Please sign in to comment.