There's always more than one way—but those can wait.
Create and use a custom weighting struct.
Calculate transaction fees by computing correct weights based on the data within a function.
Substrate provides a mechanism known as transaction weighting to quantify the resources consumed while executing a transaction. This approach to a custom weight function establishes a weight value based on some condition. Once defined, it can be used directly in your pallet, written as such:
#[weight = Conditional(200)]
Here are the different traits we'll be implementing:
WeighData: Weigh the data in a function.
PaysFee: Designate whether the dispatch pays a fee or not.
ClassifyDispatch: A way to tell the runtime about the type of dispatch being made.
1. Write the
Write an implementation of
Conditional, where the first parameter is a boolean value:
Since this implementation of
WeighData requires a
default to classify all calls as normal:
Last, specify how
PaysFee is used for the custom