Estimate call fee (#9395)

* Estimate call fee

* More fix

* Fix

* Update frame/support/src/traits/misc.rs

Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>

* try and fix fmt stuff

* fmt aain

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2021-07-23 10:53:32 +02:00
committed by GitHub
parent d18c6a5200
commit c2e246d372
8 changed files with 60 additions and 19 deletions
+15 -2
View File
@@ -52,7 +52,7 @@ use codec::{Decode, Encode};
use sp_runtime::{
traits::{
Convert, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SaturatedConversion, Saturating,
SignedExtension,
SignedExtension, Zero,
},
transaction_validity::{
TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,
@@ -63,7 +63,7 @@ use sp_std::prelude::*;
use frame_support::{
dispatch::DispatchResult,
traits::Get,
traits::{EstimateCallFee, Get},
weights::{
DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, Weight,
WeightToFeeCoefficient, WeightToFeePolynomial,
@@ -656,6 +656,19 @@ where
}
}
impl<T: Config, AnyCall: GetDispatchInfo + Encode> EstimateCallFee<AnyCall, BalanceOf<T>>
for Pallet<T>
where
BalanceOf<T>: FixedPointOperand,
T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
{
fn estimate_call_fee(call: &AnyCall, post_info: PostDispatchInfo) -> BalanceOf<T> {
let len = call.encoded_size() as u32;
let info = call.get_dispatch_info();
Self::compute_actual_fee(len, &info, &post_info, Zero::zero())
}
}
#[cfg(test)]
mod tests {
use super::*;