-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from Ronnieraj37/ccip-funding
Changes Week 10 & 11
- Loading branch information
Showing
34 changed files
with
80,980 additions
and
152,190 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
import {Errors} from "./interface/Errors.sol"; | ||
|
||
contract GeneralResult is Errors { | ||
import {Candidatecheck} from "./abstract/CandidateCheck.sol"; | ||
import {VoteWinnerCount} from "./abstract/VoteWinnerCount.sol"; | ||
import {WinnersArray} from "./abstract/WinnersArray.sol"; | ||
|
||
contract GeneralResult is | ||
Errors, | ||
Candidatecheck, | ||
VoteWinnerCount, | ||
WinnersArray | ||
{ | ||
function calculateGeneralResult( | ||
bytes calldata returnData | ||
) public pure returns (uint[] memory) { | ||
uint[] memory candidateList = abi.decode(returnData, (uint[])); | ||
uint candidatesLength = candidateList.length; | ||
|
||
if (candidatesLength == 0) { | ||
revert NoWinner(); | ||
} | ||
if (candidatesLength == 1) { | ||
uint[] memory singleWinner = new uint[](1); | ||
singleWinner[0] = 0; | ||
return singleWinner; | ||
if (candidatesLength < 2) { | ||
return checkEdgeCases(candidatesLength); | ||
} | ||
|
||
uint maxVotes = 0; | ||
uint winnerCount = 0; | ||
|
||
// First pass: find the maximum number of votes and the count of candidates with that maximum | ||
for (uint i = 0; i < candidatesLength; i++) { | ||
uint votes = candidateList[i]; | ||
if (votes > maxVotes) { | ||
maxVotes = votes; | ||
winnerCount = 1; | ||
} else if (votes == maxVotes) { | ||
winnerCount++; | ||
} | ||
} | ||
(maxVotes, winnerCount) = getVoteWinnerCount(candidateList); | ||
|
||
if (maxVotes == 0) { | ||
revert NoWinner(); | ||
} | ||
|
||
// Second pass: collect all candidates with the maximum number of votes | ||
uint[] memory winners = new uint[](winnerCount); | ||
uint numWinners = 0; | ||
|
||
for (uint i = 0; i < candidatesLength; i++) { | ||
if (candidateList[i] == maxVotes) { | ||
winners[numWinners] = i; | ||
numWinners++; | ||
} | ||
} | ||
|
||
return winners; | ||
return getWinnersArray(winnerCount, maxVotes, candidateList); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.