Implement-Decentralized-Payout-Trigger - #33
Merged
Queenode merged 3 commits intoAug 22, 2026
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
|
Thank you for your contribution @Securify001 . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes Made
Added new DataKey::CurrentCycleContributions variant to track contributions per cycle efficiently without iterating over all members.
contribute(): Now initializes CurrentCycleContributions to 0 when a new cycle starts, and increments it by 1 on each contribution.
reset_cycle(): Now resets CurrentCycleContributions to 0 when a cycle is reset.
Signature: pub fn trigger_payout(env: Env, caller: Address, recipient: Address)
Access Control: Caller must be a member (requires authentication)
Pool Fullness Check: Pool is considered full when CurrentCycleContributions == CycleMemberCount
Recipient Validation: Recipient must be a member and must not have received a payout this cycle
Payout Execution: Same logic as admin payout() function
Event: Emits trg_pay event on successful payout
✅
test_trigger_payout_success: Member triggers payout when pool is full (succeeds)✅
test_trigger_payout_pool_not_full: Member triggers payout when pool is NOT full (panics with "Pool is not full")✅
test_trigger_payout_non_member: Non-member attempts to trigger payout (panics with "Caller is not a member")Test Results
Files Modified
lib.rs- Added CurrentCycleContributions storage key, modified contribute() and reset_cycle(), added trigger_payout() functiontest.rs- Added 3 unit tests for trigger_payoutAll acceptance criteria have been met:
✅ Reduce Admin Reliance - Members can now trigger payouts
✅ Pool Fullness Check - Efficient check using CurrentCycleContributions counter
✅ Member-Triggered Payout - trigger_payout() function implemented with proper validations
✅ State Management Optimization - Counter tracks contributions efficiently
✅ Testing - All 3 required unit tests passing
Closes #21