Use Conditional Weights
Objectives
Write the Weight struct
use frame_support:: { dispatch::{DispatchClass, Pays}, }, weights::Weight,pub struct Conditional(u32); impl WeighData<(&bool, &u32)> for Conditional { fn weigh_data(&self, (switch, val): (&bool, &u32)) -> Weight { // If the first parameter is true, then the weight is linear in the second parameter. if *switch { val.saturating_mul(self.0) } // Otherwise the weight is constant. else { self.0 } } }
Classify dispatch calls
Use the weighting struct for an extrinsic
Examples
Related material
Last updated