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;

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

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

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

/// Convert a weight value into a deductible fee based on the currency type.
type WeightToFee: Convert>;

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

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(unchecked_extrinsic: Extrinsic,len: u32,) -> RuntimeDispatchInfo>
    • 询问指定调用的数据相应的费用

ChargeTransactionPayment

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

你可能感兴趣的:(Substrate的transaction-payment模块分析)