mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 07:27:55 +00:00
Allow fee calculation to happen off-chain (#6076)
* Emit a PaymentParameters event once per block This contains per-block paramaters need to calculate fees off-chain. * Add WeightToFee trait * Add documentation to polynomial types * Ignore pseudo code snippet for doc tests * Use `Mul` implementation of Perbill * Add tests for WeightToFeePolynomial * Revert "Emit a PaymentParameters event once per block" This reverts commit 6c4763baff3d8179676a3c1660fe7063fd56a8ca. Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
committed by
GitHub
parent
e04f237152
commit
9dd21b1eed
@@ -19,12 +19,15 @@ use codec::{Encode, Decode, Joiner};
|
||||
use frame_support::{
|
||||
StorageValue, StorageMap,
|
||||
traits::Currency,
|
||||
weights::{GetDispatchInfo, DispatchInfo, DispatchClass, constants::ExtrinsicBaseWeight},
|
||||
weights::{
|
||||
GetDispatchInfo, DispatchInfo, DispatchClass, constants::ExtrinsicBaseWeight,
|
||||
WeightToFeePolynomial,
|
||||
},
|
||||
};
|
||||
use sp_core::{NeverNativeValue, traits::Externalities, storage::well_known_keys};
|
||||
use sp_runtime::{
|
||||
ApplyExtrinsicResult, Fixed128,
|
||||
traits::{Hash as HashT, Convert},
|
||||
traits::Hash as HashT,
|
||||
transaction_validity::InvalidTransaction,
|
||||
};
|
||||
use pallet_contracts::ContractAddressFor;
|
||||
@@ -54,9 +57,9 @@ fn transfer_fee<E: Encode>(extrinsic: &E, fee_multiplier: Fixed128) -> Balance {
|
||||
let length_fee = TransactionByteFee::get() * (extrinsic.encode().len() as Balance);
|
||||
|
||||
let base_weight = ExtrinsicBaseWeight::get();
|
||||
let base_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(base_weight);
|
||||
let base_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&base_weight);
|
||||
let weight = default_transfer_call().get_dispatch_info().weight;
|
||||
let weight_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(weight);
|
||||
let weight_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight);
|
||||
|
||||
base_fee + fee_multiplier.saturated_multiply_accumulate(length_fee + weight_fee)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user