mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 15:15:42 +00:00
FRAME: inherited call weight syntax (#13932)
* First approach on pallet::call_weight Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use attr on pallet::call instead Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Ui tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Rename to weight(prefix = ...)) Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Simplify to #[pallet::call(weight(T))] Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add stray token error Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Cleanup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Migrate remaining pallets Using script from https://github.com/ggwpez/substrate-scripts/blob/e1b5ea5b5b4018867f3e869fce6f448b4ba9d71f/frame-code-migration/src/call_weight.rs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Try to add some docs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Migrate remaining pallets" Lets do this as a follow-up, I dont want to bloat this small MR. This reverts commit 331d4b42d72de1dacaed714d69166fa1bc9c92dd. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Renames Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review fixes Co-authored-by: Sam Johnson <sam@durosoft.com> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update UI tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/pallet/parse/mod.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Remove old code Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update docs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: parity-processbot <> Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6e5141fc23
commit
b5201fa0ec
@@ -15,8 +15,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{pallet::Def, COUNTER};
|
||||
use quote::ToTokens;
|
||||
use crate::{
|
||||
pallet::{parse::call::CallWeightDef, Def},
|
||||
COUNTER,
|
||||
};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
///
|
||||
@@ -74,15 +78,12 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
call_index_warnings.push(warning);
|
||||
}
|
||||
|
||||
let fn_weight = methods.iter().map(|method| &method.weight);
|
||||
let mut fn_weight = Vec::<TokenStream2>::new();
|
||||
let mut weight_warnings = Vec::new();
|
||||
for weight in fn_weight.clone() {
|
||||
if def.dev_mode {
|
||||
continue
|
||||
}
|
||||
|
||||
match weight {
|
||||
syn::Expr::Lit(lit) => {
|
||||
for method in &methods {
|
||||
match &method.weight {
|
||||
CallWeightDef::DevModeDefault => fn_weight.push(syn::parse_quote!(0)),
|
||||
CallWeightDef::Immediate(e @ syn::Expr::Lit(lit)) if !def.dev_mode => {
|
||||
let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight")
|
||||
.index(weight_warnings.len())
|
||||
.old("use hard-coded constant as call weight")
|
||||
@@ -91,10 +92,26 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
.span(lit.span())
|
||||
.build();
|
||||
weight_warnings.push(warning);
|
||||
fn_weight.push(e.into_token_stream());
|
||||
},
|
||||
CallWeightDef::Immediate(e) => fn_weight.push(e.into_token_stream()),
|
||||
CallWeightDef::Inherited => {
|
||||
let pallet_weight = def
|
||||
.call
|
||||
.as_ref()
|
||||
.expect("we have methods; we have calls; qed")
|
||||
.inherited_call_weight
|
||||
.as_ref()
|
||||
.expect("the parser prevents this");
|
||||
|
||||
// Expand `<<T as Config>::WeightInfo>::call_name()`.
|
||||
let t = &pallet_weight.typename;
|
||||
let n = &method.name;
|
||||
fn_weight.push(quote!({ < #t > :: #n () }));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
debug_assert_eq!(fn_weight.len(), methods.len());
|
||||
|
||||
let fn_doc = methods.iter().map(|method| &method.docs).collect::<Vec<_>>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user