2

I am trying to understand slashing and rewarding funds from the recipe example.

https://substrate.recipes/currency-imbalances.html

For slashing funds it doesn't require initialization with <NegativeImbalanceOf>::zero() whereas for rewarding funds it requires initializing <PositiveImbalanceOf>::zero()

 //slash fund     
 let imbalance = T::Currency::slash_reserved(&to_punish, collateral).0;
 T::Slash::on_unbalanced(imbalance);

 //reward funds
 let mut total_imbalance = <PositiveImbalanceOf<T>>::zero(); 
 let r = T::Currency::deposit_into_existing(&to_reward, reward).ok();
 total_imbalance.maybe_subsume(r);
 T::Reward::on_unbalanced(total_imbalance);

What does the two extra lines of code do in reward funds, do I have to use it every time I reward funds??

1
  • So you are asking about the syntax here? You can probably re-write it. Commented Mar 19, 2022 at 15:13

1 Answer 1

2

There seems to be no difference here. You can probably simplify the code to:

 //slash fund     
 let imbalance = T::Currency::slash_reserved(&to_punish, collateral).0;
 T::Slash::on_unbalanced(imbalance);

 //reward funds
 let r = T::Currency::deposit_into_existing(&to_reward, reward).ok().unwrap();
 T::Reward::on_unbalanced(r);

Why it was written this way, I cannot speak to, but there is no magic happening or difference between NegativeImbalanceOf and PositiveImbalanceOf.

2
  • Yes, its gives an type error. One has to unwrap it T::Currency::deposit_into_existing(&to_reward, reward).ok().unwrap(); to get r as PositiveImbalance type Commented Mar 20, 2022 at 7:54
  • thanks, updated
    – Shawn Tabrizi
    Commented Mar 20, 2022 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.