Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Clarify wieght traits needed to impl in example #9842

Merged
merged 5 commits into from
Oct 18, 2021

Conversation

nuke-web3
Copy link
Contributor

Discovered inconsistency with devhub here: polkadot-developers/substrate-developer-hub.github.io#1125

Add a required third trait in the docs as evidenced here:

struct WeightForSetDummy<T: pallet_balances::Config>(BalanceOf<T>);
impl<T: pallet_balances::Config> WeighData<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
fn weigh_data(&self, target: (&BalanceOf<T>,)) -> Weight {
let multiplier = self.0;
// *target.0 is the amount passed into the extrinsic
let cents = *target.0 / <BalanceOf<T>>::from(MILLICENTS);
(cents * multiplier).saturated_into::<Weight>()
}
}
impl<T: pallet_balances::Config> ClassifyDispatch<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
fn classify_dispatch(&self, target: (&BalanceOf<T>,)) -> DispatchClass {
if *target.0 > <BalanceOf<T>>::from(1000u32) {
DispatchClass::Operational
} else {
DispatchClass::Normal
}
}
}
impl<T: pallet_balances::Config> PaysFee<(&BalanceOf<T>,)> for WeightForSetDummy<T> {
fn pays_fee(&self, _target: (&BalanceOf<T>,)) -> Pays {
Pays::Yes
}
}

@nuke-web3 nuke-web3 added Z0-trivial Writing the issue is of the same difficulty as patching the code. A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit and removed Z0-trivial Writing the issue is of the same difficulty as patching the code. labels Sep 23, 2021
frame/example/src/lib.rs Outdated Show resolved Hide resolved
frame/example/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also improve the doc in frame/support/src/lib.rs when explaining about the pallet::weight attribute.

frame/example/src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
@gui1117
Copy link
Contributor

gui1117 commented Oct 18, 2021

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit d1ec40b into master Oct 18, 2021
@paritytech-processbot paritytech-processbot bot deleted the NukeManDan-patch-1 branch October 18, 2021 10:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants