Do a refund based on the actual weight (#5584)

This refunds weight and the weight bases fee back
to the sender of an extrinsic after the dispatch.
This commit is contained in:
Alexander Theißen
2020-04-11 13:56:29 +02:00
committed by GitHub
parent 8e0d01570f
commit bd91e58a9a
4 changed files with 131 additions and 60 deletions
+15
View File
@@ -139,6 +139,21 @@ pub struct PostDispatchInfo {
pub actual_weight: Option<Weight>,
}
impl PostDispatchInfo {
/// Calculate how much (if any) weight was not used by the `Dispatchable`.
pub fn calc_unspent(&self, info: &DispatchInfo) -> Weight {
if let Some(actual_weight) = self.actual_weight {
if actual_weight >= info.weight {
0
} else {
info.weight - actual_weight
}
} else {
0
}
}
}
impl From<Option<Weight>> for PostDispatchInfo {
fn from(actual_weight: Option<Weight>) -> Self {
Self {