Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Correctly serialize code in chain spec as hex #4025

Merged
merged 5 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use quote::quote;
use super::super::{DeclStorageDefExt, StorageLineTypeDef};

pub struct GenesisConfigFieldDef {
pub doc: Vec<syn::Meta>,
pub name: syn::Ident,
pub typ: syn::Type,
pub attrs: Vec<syn::Meta>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub attrs: Vec<syn::Meta>,
pub attrs: Vec<syn::Attribute>,

pub default: TokenStream,
}

Expand Down Expand Up @@ -114,27 +114,26 @@ impl GenesisConfigDef {
.unwrap_or_else(|| quote!( Default::default() ));

config_field_defs.push(GenesisConfigFieldDef {
doc: line.doc_attrs.clone(),
name: config_field,
typ,
attrs: line.doc_attrs.clone(),
default,
});
}

for line in &def.extra_genesis_config_lines {
let doc = line.attrs.iter()
.filter_map(|a| a.parse_meta().ok())
.filter(|m| m.name() == "doc")
let attrs = line.attrs.iter()
.map(|a| a.parse_meta().expect("attribute cannot be parsed"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First rule of the macro club, never panic ;)

If we want to accept all attributes here, we don't need to parse them.

Just store syn::Attribute in attrs.

So:
let attrs = line.attrs.clone()

.collect();

let default = line.default.as_ref().map(|e| quote!( #e ))
.unwrap_or_else(|| quote!( Default::default() ));


config_field_defs.push(GenesisConfigFieldDef {
doc,
name: line.name.clone(),
typ: line.typ.clone(),
attrs,
default,
});
}
Expand Down
8 changes: 4 additions & 4 deletions srml/support/procedural/src/storage/genesis_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ fn decl_genesis_config_and_impl_default(
genesis_config: &GenesisConfigDef,
) -> TokenStream {
let config_fields = genesis_config.fields.iter().map(|field| {
let (name, typ, doc) = (&field.name, &field.typ, &field.doc);
quote!( #( #[ #doc] )* pub #name: #typ, )
let (name, typ, attrs) = (&field.name, &field.typ, &field.attrs);
quote!( #( #[ #attrs] )* pub #name: #typ, )
});

let config_field_defaults = genesis_config.fields.iter().map(|field| {
let (name, default, doc) = (&field.name, &field.default, &field.doc);
quote!( #( #[ #doc] )* #name: #default, )
let (name, default) = (&field.name, &field.default);
quote!( #name: #default, )
});

let serde_bug_bound = if !genesis_config.fields.is_empty() {
Expand Down