提取一些可用余额时如何打印值 NegativeImbalance余额托盘

问题描述

在我的代码中:

let withdraw_balance = <pallet_balances::Module<T> as Currency<_>>::withdraw(&participant,workshop.fee,WithdrawReasons::RESERVE,ExistenceRequirement::KeepAlive);

我就是这样调试的

frame_support::debug::native::debug!("withdraw_balance:{:#?}",withdraw_balance);

这是错误的,因为这个特征没有为 NegativeImbalance 实现 std::fmt::Debug。 我尝试为 NegativeImbalance 实现调试,但我失败了(我是新手)。虽然,当我在 Substrate 中阅读 doc 时,他们给出了一些提示来为 struct NegativeImbalance (https://substrate.dev/rustdocs/v3.0.0-monthly-2021-05/pallet_balances/struct.NegativeImbalance.html) 实现调试,如下所示: implement Trait Debug for struct NegativeImbalance

谢谢!!!

提取了一些这样的代码:(我关注 1 个博客,完整代码在这里https://arveknudsen.com/posts/substrate-runtime-module/

#[weight=10_000]
fn participate(origin) -> dispatch::dispatchResult{
    let participant = ensure_signed(origin)?;

    frame_support::debug::native::debug!("sender:{}",participant);
   
    let workshop = match <Workshop<T>>::get() {
        Some(workshop) => {
            Ok(workshop)
        }
        None => {
            Err("no workshop announced")
        }
    }?;

    let mut members = <Members<T>>::get();

    match members.binary_search(&participant){

        Ok(_) => Err(Error::<T>::AlreadyParticipant.into()),Err(index) => {
            members.insert(index,participant.clone());
            Members::<T>::put(members);
            Self::deposit_event(RawEvent::AddParticipants(participant.clone()));

            let mut num_participants = <NumParticipants>::get();
            frame_support::debug::native::debug!("num_participants:{}",num_participants);

            for i in 0..num_participants {
                let acc_id = <Participants<T>>::get(i);
                if acc_id == participant.clone() {
                    return Ok(());
                }
            }
            let withdraw_balance = <pallet_balances::Module<T> as Currency<_>>::withdraw(&participant,ExistenceRequirement::KeepAlive)?;
            frame_support::debug::native::debug!("withdraw_balance:{:#?}",withdraw_balance);
            frame_support::debug::native::debug!("total_issuancei_after_withdraw:{:?}",<pallet_balances::Module<T> as Currency<_>>::total_issuance());
            frame_support::debug::native::debug!("total_balance_after_withdraw:{:?}",<pallet_balances::Module<T> as Currency<_>>::total_balance(&participant));
            <Participants<T>>::insert(num_participants,&participant);
            num_participants = num_participants.saturating_add(1);
            frame_support::debug::native::debug!("num_participants_after_insert:{}",num_participants);
            <NumParticipants>::put(num_participants);

            let mut budget = <Budget<T>>::get();
            //budget = budget.into() + workshop.unwrap().fee;
            let mut budget_u32 = TryInto::<u32>::try_into(budget).ok().unwrap();
            //let fee_u32 = TryInto::<u32>::try_into(workshop.as_ref().unwrap().fee).ok().unwrap();
            let fee_u32 = TryInto::<u32>::try_into(workshop.fee).ok().unwrap();
            budget_u32 = budget_u32.saturating_add(fee_u32);

            frame_support::debug::native::debug!("budget_u32:{}",budget_u32);
            budget = budget_u32.into();

            <Budget<T>>::put(budget);

            Ok(())

        }


    }

}

我有这样的错误Bug

目的:我想深入了解 Balance Pallet 并检查一些术语,例如 Imbalance / NegativeImbalance/ PositiveImbalance/ Total Issuance,...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)