Add WeightToFee and LengthToFee impls to transaction-payment Runtime API (#13110)

* Add WeightToFee and LengthToFee impls to RPC

* Remove RPC additions

* Update frame/transaction-payment/rpc/runtime-api/src/lib.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Add comments to length_to_fee and weight_to_fee

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Stephen Shelton
2023-01-26 07:39:20 -07:00
committed by GitHub
parent 64b55cb170
commit 702963fea4
4 changed files with 39 additions and 4 deletions
@@ -612,11 +612,14 @@ where
}
}
fn length_to_fee(length: u32) -> BalanceOf<T> {
/// Compute the length portion of a fee by invoking the configured `LengthToFee` impl.
pub fn length_to_fee(length: u32) -> BalanceOf<T> {
T::LengthToFee::weight_to_fee(&Weight::from_ref_time(length as u64))
}
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
/// Compute the unadjusted portion of the weight fee by invoking the configured `WeightToFee`
/// impl. Note that the input `weight` is capped by the maximum block weight before computation.
pub fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
// cap the weight to the maximum defined in runtime, otherwise it will be the
// `Bounded` maximum of its data type, which is not desired.
let capped_weight = weight.min(T::BlockWeights::get().max_block);