referrerpolicy=no-referrer-when-downgrade

frame_support_procedural/pallet/expand/
genesis_build.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use crate::pallet::Def;
19
20///
21/// * implement the trait `sp_runtime::BuildStorage`
22pub fn expand_genesis_build(def: &mut Def) -> proc_macro2::TokenStream {
23	let genesis_config = if let Some(genesis_config) = &def.genesis_config {
24		genesis_config
25	} else {
26		return Default::default()
27	};
28	let genesis_build = def.genesis_build.as_ref().expect("Checked by def parser");
29
30	let frame_support = &def.frame_support;
31	let type_impl_gen = &genesis_config.gen_kind.type_impl_gen(genesis_build.attr_span);
32	let gen_cfg_ident = &genesis_config.genesis_config;
33	let gen_cfg_use_gen = &genesis_config.gen_kind.type_use_gen(genesis_build.attr_span);
34
35	let where_clause = &genesis_build.where_clause;
36
37	quote::quote_spanned!(genesis_build.attr_span =>
38		#frame_support::std_enabled! {
39			impl<#type_impl_gen> #frame_support::sp_runtime::BuildStorage for #gen_cfg_ident<#gen_cfg_use_gen> #where_clause
40			{
41				fn assimilate_storage(&self, storage: &mut #frame_support::sp_runtime::Storage) -> std::result::Result<(), std::string::String> {
42					#frame_support::__private::BasicExternalities::execute_with_storage(storage, || {
43						self.build();
44						Ok(())
45					})
46				}
47			}
48		}
49	)
50}