美文网首页
Substrate的transaction-payment模块分

Substrate的transaction-payment模块分

作者: 建怀 | 来源:发表于2019-11-28 19:07 被阅读0次

    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>

    相关文章

      网友评论

          本文标题:Substrate的transaction-payment模块分

          本文链接:https://www.haomeiwen.com/subject/zvqiwctx.html