在我的代码中,我有:
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 中阅读文档时,他们给出了一些提示来实现 struct NegativeImbalance 的调试(https://substrate.dev/rustdocs/v3.0.0-monthly-2021-05/pallet_balances/struct.NegativeImbalance.html)像这样: 为 struct NegativeImbalance 实现 Trait Debug
谢谢!!!
我提取了一些这样的代码:(我关注 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,workshop.fee,WithdrawReasons::RESERVE,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(())
}
}
}
我有这样的错误: 错误
目的:我想深入了解 Balance Pallet 并检查一些术语,例如 Imbalance / NegativeImbalance / PositiveImbalance / Total Issuance,...