working_group.rs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. use frame_support::StorageMap;
  2. use sp_std::marker::PhantomData;
  3. use crate::{
  4. ContentWorkingGroupInstance, DistributionWorkingGroupInstance, GatewayWorkingGroupInstance,
  5. OperationsWorkingGroupInstanceAlpha, OperationsWorkingGroupInstanceBeta,
  6. OperationsWorkingGroupInstanceGamma, StorageWorkingGroupInstance,
  7. };
  8. use stake::{BalanceOf, NegativeImbalance};
  9. macro_rules! wg_staking_event_impl {
  10. ($operation_wg_instance:ident, $operation_wg_staking_event_handler:ty) => {
  11. impl<T: stake::Trait + working_group::Trait<$operation_wg_instance>>
  12. stake::StakingEventsHandler<T> for $operation_wg_staking_event_handler
  13. {
  14. /// Unstake remaining sum back to the source_account_id
  15. fn unstaked(
  16. stake_id: &<T as stake::Trait>::StakeId,
  17. _unstaked_amount: BalanceOf<T>,
  18. remaining_imbalance: NegativeImbalance<T>,
  19. ) -> NegativeImbalance<T> {
  20. // Stake not related to a staked role managed by the hiring module.
  21. if !hiring::ApplicationIdByStakingId::<T>::contains_key(*stake_id) {
  22. return remaining_imbalance;
  23. }
  24. let hiring_application_id = hiring::ApplicationIdByStakingId::<T>::get(*stake_id);
  25. if working_group::MemberIdByHiringApplicationId::<T, $operation_wg_instance>::contains_key(
  26. hiring_application_id,
  27. ) {
  28. return <working_group::Module<T, $operation_wg_instance>>::refund_working_group_stake(
  29. *stake_id,
  30. remaining_imbalance,
  31. );
  32. }
  33. remaining_imbalance
  34. }
  35. /// Empty handler for the slashing.
  36. fn slashed(
  37. _: &<T as stake::Trait>::StakeId,
  38. _: Option<<T as stake::Trait>::SlashId>,
  39. _: BalanceOf<T>,
  40. _: BalanceOf<T>,
  41. remaining_imbalance: NegativeImbalance<T>,
  42. ) -> NegativeImbalance<T> {
  43. remaining_imbalance
  44. }
  45. }
  46. }
  47. }
  48. // Will be removed in the next releases.
  49. #[allow(clippy::upper_case_acronyms)]
  50. pub struct ContentDirectoryWgStakingEventsHandler<T> {
  51. pub marker: PhantomData<T>,
  52. }
  53. pub struct StorageWgStakingEventsHandler<T> {
  54. pub marker: PhantomData<T>,
  55. }
  56. pub struct OperationsWgStakingEventsHandlerAlpha<T> {
  57. pub marker: PhantomData<T>,
  58. }
  59. pub struct OperationsWgStakingEventsHandlerBeta<T> {
  60. pub marker: PhantomData<T>,
  61. }
  62. pub struct OperationsWgStakingEventsHandlerGamma<T> {
  63. pub marker: PhantomData<T>,
  64. }
  65. pub struct GatewayWgStakingEventsHandler<T> {
  66. pub marker: PhantomData<T>,
  67. }
  68. pub struct DistributionWgStakingEventsHandler<T> {
  69. pub marker: PhantomData<T>,
  70. }
  71. wg_staking_event_impl!(
  72. ContentWorkingGroupInstance,
  73. ContentDirectoryWgStakingEventsHandler<T>
  74. );
  75. wg_staking_event_impl!(
  76. StorageWorkingGroupInstance,
  77. StorageWgStakingEventsHandler<T>
  78. );
  79. wg_staking_event_impl!(
  80. GatewayWorkingGroupInstance,
  81. GatewayWgStakingEventsHandler<T>
  82. );
  83. wg_staking_event_impl!(
  84. OperationsWorkingGroupInstanceAlpha,
  85. OperationsWgStakingEventsHandlerAlpha<T>
  86. );
  87. wg_staking_event_impl!(
  88. OperationsWorkingGroupInstanceBeta,
  89. OperationsWgStakingEventsHandlerBeta<T>
  90. );
  91. wg_staking_event_impl!(
  92. OperationsWorkingGroupInstanceGamma,
  93. OperationsWgStakingEventsHandlerGamma<T>
  94. );
  95. wg_staking_event_impl!(
  96. DistributionWorkingGroupInstance,
  97. DistributionWgStakingEventsHandler<T>
  98. );