refactor(Election): Extract duplicated ballot init into ensureBallot modifier#246
refactor(Election): Extract duplicated ballot init into ensureBallot modifier#246Muneerali199 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Conversation
userVote() and ccipVote() both contained an identical 3-line block
to lazily initialise the ballot on first vote:
if (ballotInitialized == false) {
ballot.init(candidates.length);
ballotInitialized = true;
}
Copy-pasting this logic across two functions is error-prone: a future
bug-fix or change (e.g. passing different args to init) would need to
be applied in both places, and it is easy to miss one.
Extract the block into a dedicated modifier ensureBallot() and apply
it to both functions. Behaviour is identical; only the structure changes.
Closes AOSSIE-Org#230
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Summary
Eliminates a copy-pasted lazy-initialization block that existed identically in two functions, replacing it with a single
ensureBallotmodifier.Closes #230
Problem
Both
userVote()andccipVote()contained the identical 3-line block:This duplication means:
Fix
Extracted the block into a
ensureBallotmodifier and applied it to both functions:Same change applied to
ccipVote(). Runtime behaviour is identical — only the structure changes.Files Changed
blockchain/contracts/Election.solensureBallotmodifier; removed duplicated init blocks fromuserVote()andccipVote()Checklist
userVoteandccipVoteretain correct modifier order (electionInactivebeforeensureBallot)upstream/main