Substrate的transaction-payment模塊分析

Substrate的transaction-payment模塊分析

transaction-payment模塊提供了轉賬包括的最小數量的手續費收取邏輯。

  • weight fee:根據一個交易所△消耗重量成比例的手續費。
  • length fee:根據」一個交易編碼後長度成比例的手續費。
  • tip:加速小費,更高小費,更快進入交易隊列。

額外,還可以允許去配≡置如下:

  • [WeightToFee] : 一個單位的重點對應到的↘費用設置mapping。
  • [FeeMultiplierUpdate] : 基於←之前一個區塊的重量,乘以一個multiplier,用來更新下一個區△塊的費用。

Trait

/// The currency type in which fees will be paid.
type Currency: Currency<Self::AccountId>;

/// Handler for the unbalanced reduction when taking transaction fees.
type OnTransactionPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;

/// The fee to be paid for making a transaction; the base.
type TransactionBaseFee: Get<BalanceOf<Self>>;

/// The fee to be paid for making a transaction; the per-byte portion.
type TransactionByteFee: Get<BalanceOf<Self>>;

/// Convert a weight value into a deductible fee based on the currency type.
type WeightToFee: Convert<Weight, BalanceOf<Self>>;

/// Update the multiplier of the next block, based on the previous block's weight.
type FeeMultiplierUpdate: Convert<Multiplier, Multiplier>;

Store

NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_parts(0);

Module

fn on_finalize() {
    NextFeeMultiplier::mutate(|fm| {
        *fm = T::FeeMultiplierUpdate::convert(*fm)
    });
}
  • pub fn query_info<Extrinsic: GetDispatchInfo>(unchecked_extrinsic: Extrinsic,len: u32,) -> RuntimeDispatchInfo<BalanceOf<T>>
    • 詢問指定調用的數據〇相應的費用

ChargeTransactionPayment

pub struct ChargeTransactionPayment<T: Trait + Send + Sync>(#[codec(compact)] BalanceOf<T>);
  • fn compute_fee(len: u32,info: DispatchInfo, tip: BalanceOf<T>) -> BalanceOf<T>

推薦閱讀更多精彩☆內容