mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 02:25:41 +00:00
878c562cd4
* make reexports private * make reexports private 2 * make reexports private for runtime-benchmarking * make reexports private for try-runtime * fix for try-runtime * make reexports private for tests * fmt * make reexports private for tests * make reexports private for experimental * fix beefy * fix ui test * fix ui test * fix benches * ".git/.scripts/commands/fmt/fmt.sh" * fix contracts use * wip * wip * do not reexport sp_api::metadata_ir * fix CI checks * fix support tests * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/support/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * import codec directly * fmt * fix node-cli tests --------- Co-authored-by: command-bot <> Co-authored-by: Bastian Köcher <git@kchr.de>
109 lines
3.6 KiB
Rust
109 lines
3.6 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use crate::pallet::Def;
|
|
|
|
struct ConstDef {
|
|
/// Name of the associated type.
|
|
pub ident: syn::Ident,
|
|
/// The type in Get, e.g. `u32` in `type Foo: Get<u32>;`, but `Self` is replaced by `T`
|
|
pub type_: syn::Type,
|
|
/// The doc associated
|
|
pub doc: Vec<syn::Expr>,
|
|
/// default_byte implementation
|
|
pub default_byte_impl: proc_macro2::TokenStream,
|
|
/// Constant name for Metadata (optional)
|
|
pub metadata_name: Option<syn::Ident>,
|
|
}
|
|
|
|
///
|
|
/// * Impl fn module_constant_metadata for pallet.
|
|
pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
|
|
let frame_support = &def.frame_support;
|
|
let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site());
|
|
let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site());
|
|
let pallet_ident = &def.pallet_struct.pallet;
|
|
let trait_use_gen = &def.trait_use_generics(proc_macro2::Span::call_site());
|
|
|
|
let mut where_clauses = vec![&def.config.where_clause];
|
|
where_clauses.extend(def.extra_constants.iter().map(|d| &d.where_clause));
|
|
let completed_where_clause = super::merge_where_clauses(&where_clauses);
|
|
|
|
let config_consts = def.config.consts_metadata.iter().map(|const_| {
|
|
let ident = &const_.ident;
|
|
let const_type = &const_.type_;
|
|
|
|
ConstDef {
|
|
ident: const_.ident.clone(),
|
|
type_: const_.type_.clone(),
|
|
doc: const_.doc.clone(),
|
|
default_byte_impl: quote::quote!(
|
|
let value = <<T as Config #trait_use_gen>::#ident as
|
|
#frame_support::traits::Get<#const_type>>::get();
|
|
#frame_support::__private::codec::Encode::encode(&value)
|
|
),
|
|
metadata_name: None,
|
|
}
|
|
});
|
|
|
|
let extra_consts = def.extra_constants.iter().flat_map(|d| &d.extra_constants).map(|const_| {
|
|
let ident = &const_.ident;
|
|
|
|
ConstDef {
|
|
ident: const_.ident.clone(),
|
|
type_: const_.type_.clone(),
|
|
doc: const_.doc.clone(),
|
|
default_byte_impl: quote::quote!(
|
|
let value = <Pallet<#type_use_gen>>::#ident();
|
|
#frame_support::__private::codec::Encode::encode(&value)
|
|
),
|
|
metadata_name: const_.metadata_name.clone(),
|
|
}
|
|
});
|
|
|
|
let consts = config_consts.chain(extra_consts).map(|const_| {
|
|
let const_type = &const_.type_;
|
|
let ident_str = format!("{}", const_.metadata_name.unwrap_or(const_.ident));
|
|
|
|
let no_docs = vec![];
|
|
let doc = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &const_.doc };
|
|
|
|
let default_byte_impl = &const_.default_byte_impl;
|
|
|
|
quote::quote!({
|
|
#frame_support::__private::metadata_ir::PalletConstantMetadataIR {
|
|
name: #ident_str,
|
|
ty: #frame_support::__private::scale_info::meta_type::<#const_type>(),
|
|
value: { #default_byte_impl },
|
|
docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ],
|
|
}
|
|
})
|
|
});
|
|
|
|
quote::quote!(
|
|
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause{
|
|
|
|
#[doc(hidden)]
|
|
pub fn pallet_constants_metadata()
|
|
-> #frame_support::__private::sp_std::vec::Vec<#frame_support::__private::metadata_ir::PalletConstantMetadataIR>
|
|
{
|
|
#frame_support::__private::sp_std::vec![ #( #consts ),* ]
|
|
}
|
|
}
|
|
)
|
|
}
|