如何解决提取一些可用余额时如何打印值 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(())
}
}
}
目的:我想深入了解 Balance Pallet 并检查一些术语,例如 Imbalance / NegativeImbalance/ PositiveImbalance/ Total Issuance,...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。