PaysFee for DispatchInfo (#4165)

* Add PaysFee trait

* bump version

* Apply suggestions from code review

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* line width

* Apply suggestions from code review

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* fix test

* fix test

* fix test
This commit is contained in:
Xiliang Chen
2019-11-25 19:42:51 +13:00
committed by Kian Paimani
parent 68818929ab
commit 04571d958b
7 changed files with 81 additions and 54 deletions
+12 -6
View File
@@ -25,7 +25,7 @@ pub use frame_metadata::{
};
pub use crate::weights::{
SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch,
TransactionPriority, Weight, WeighBlock,
TransactionPriority, Weight, WeighBlock, PaysFee,
};
pub use sr_primitives::{
traits::{Dispatchable, DispatchResult, ModuleDispatchError},
@@ -1321,7 +1321,10 @@ macro_rules! decl_module {
&$weight,
($( $param_name, )*)
);
return $crate::dispatch::DispatchInfo { weight, class };
let pays_fee = <dyn $crate::dispatch::PaysFee>::pays_fee(
&$weight
);
return $crate::dispatch::DispatchInfo { weight, class, pays_fee };
}
if let $call_type::__PhantomItem(_, _) = self { unreachable!("__PhantomItem should never be used.") }
)*
@@ -1337,7 +1340,10 @@ macro_rules! decl_module {
&$crate::dispatch::SimpleDispatchInfo::default(),
()
);
$crate::dispatch::DispatchInfo { weight, class }
let pays_fee = <dyn $crate::dispatch::PaysFee>::pays_fee(
&$crate::dispatch::SimpleDispatchInfo::default()
);
$crate::dispatch::DispatchInfo { weight, class, pays_fee }
}
}
@@ -2066,17 +2072,17 @@ mod tests {
// operational.
assert_eq!(
Call::<TraitImpl>::operational().get_dispatch_info(),
DispatchInfo { weight: 5, class: DispatchClass::Operational },
DispatchInfo { weight: 5, class: DispatchClass::Operational, pays_fee: true },
);
// default weight.
assert_eq!(
Call::<TraitImpl>::aux_0().get_dispatch_info(),
DispatchInfo { weight: 10_000, class: DispatchClass::Normal },
DispatchInfo { weight: 10_000, class: DispatchClass::Normal, pays_fee: true },
);
// custom basic
assert_eq!(
Call::<TraitImpl>::aux_3().get_dispatch_info(),
DispatchInfo { weight: 3, class: DispatchClass::Normal },
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: true },
);
}