Skip to content

Commit ceabb37

Browse files
committed
TEST PENDING: use 1900 epoch
Signed-off-by: John Titor <[email protected]>
1 parent b48fdc2 commit ceabb37

File tree

6 files changed

+408
-76
lines changed

6 files changed

+408
-76
lines changed

contracts/CandidateDatabase.sol

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
4545
string qualifications;
4646
string manifesto;
4747
Gender gender;
48-
uint256 dateOfBirthEpoch;
49-
uint256 registrationTimestamp;
48+
uint256 dateOfBirthEpoch1900; // Date of birth in Epoch1900 format
49+
uint256 registrationTimestamp1900; // Registration time in Epoch1900 format
5050
}
5151

5252
/// @dev Main storage for candidate information
@@ -57,10 +57,10 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
5757

5858
/**
5959
* @notice Ensures the candidate meets minimum age requirements
60-
* @param _dateOfBirthEpoch Date of birth as Unix timestamp
60+
* @param _dateOfBirthEpoch1900 Date of birth as Epoch1900 timestamp
6161
*/
62-
modifier onlyEligible(uint256 _dateOfBirthEpoch) {
63-
if (ElectionUtils.calculateAge(_dateOfBirthEpoch) < MIN_ELIGIBLE_AGE)
62+
modifier onlyEligible(uint256 _dateOfBirthEpoch1900) {
63+
if (ElectionUtils.calculateAge(_dateOfBirthEpoch1900) < MIN_ELIGIBLE_AGE)
6464
revert CandidateDatabase__NotEligible();
6565
_;
6666
}
@@ -70,7 +70,7 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
7070
* @param _candidateAddress Address to check for registration
7171
*/
7272
modifier onlyRegistered(address _candidateAddress) {
73-
if (s_candidates[_candidateAddress].registrationTimestamp == 0)
73+
if (s_candidates[_candidateAddress].registrationTimestamp1900 == 0)
7474
revert CandidateDatabase__NotRegistered();
7575
_;
7676
}
@@ -80,7 +80,7 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
8080
* @param _candidateAddress Address to check for registration
8181
*/
8282
modifier onlyNotRegistered(address _candidateAddress) {
83-
if (s_candidates[_candidateAddress].registrationTimestamp > 0)
83+
if (s_candidates[_candidateAddress].registrationTimestamp1900 > 0)
8484
revert CandidateDatabase__AlreadyRegistered();
8585
_;
8686
}
@@ -100,7 +100,7 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
100100
* @dev Used by both self-registration and admin functions
101101
* @param _candidateAddress Address of the candidate to add
102102
* @param _name Name of the candidate
103-
* @param _dateOfBirthEpoch Date of birth as Unix timestamp
103+
* @param _dateOfBirthEpoch1900 Date of birth as Epoch1900 timestamp
104104
* @param _gender Gender of the candidate
105105
* @param _presentAddress Present address of the candidate
106106
* @param _email Email address of the candidate
@@ -110,26 +110,26 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
110110
function _addCandidate(
111111
address _candidateAddress,
112112
string memory _name,
113-
uint256 _dateOfBirthEpoch,
113+
uint256 _dateOfBirthEpoch1900,
114114
Gender _gender,
115115
string memory _presentAddress,
116116
string memory _email,
117117
string memory _qualifications,
118118
string memory _manifesto
119119
)
120120
internal
121-
onlyEligible(_dateOfBirthEpoch)
121+
onlyEligible(_dateOfBirthEpoch1900)
122122
onlyNotRegistered(_candidateAddress)
123123
{
124124
s_candidates[_candidateAddress] = Candidate({
125125
name: _name,
126-
dateOfBirthEpoch: _dateOfBirthEpoch,
126+
dateOfBirthEpoch1900: _dateOfBirthEpoch1900,
127127
gender: _gender,
128128
presentAddress: _presentAddress,
129129
email: _email,
130130
qualifications: _qualifications,
131131
manifesto: _manifesto,
132-
registrationTimestamp: block.timestamp
132+
registrationTimestamp1900: ElectionUtils.getNowEpoch1900()
133133
});
134134

135135
s_candidateAddresses.push(_candidateAddress);
@@ -140,7 +140,7 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
140140
* @dev Used by both self-update and admin functions
141141
* @param _candidateAddress Address of the candidate to update
142142
* @param _name Updated name
143-
* @param _dateOfBirthEpoch Updated date of birth as Unix timestamp
143+
* @param _dateOfBirthEpoch1900 Updated date of birth as Epoch1900 timestamp
144144
* @param _gender Updated gender
145145
* @param _presentAddress Updated present address
146146
* @param _email Updated email address
@@ -150,22 +150,22 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
150150
function _updateCandidate(
151151
address _candidateAddress,
152152
string memory _name,
153-
uint256 _dateOfBirthEpoch,
153+
uint256 _dateOfBirthEpoch1900,
154154
Gender _gender,
155155
string memory _presentAddress,
156156
string memory _email,
157157
string memory _qualifications,
158158
string memory _manifesto
159159
)
160160
internal
161-
onlyEligible(_dateOfBirthEpoch)
161+
onlyEligible(_dateOfBirthEpoch1900)
162162
onlyRegistered(_candidateAddress)
163163
{
164164
Candidate storage candidate = s_candidates[_candidateAddress];
165165

166-
// Update details but preserve registrationTimestamp
166+
// Update details but preserve registrationTimestamp1900
167167
candidate.name = _name;
168-
candidate.dateOfBirthEpoch = _dateOfBirthEpoch;
168+
candidate.dateOfBirthEpoch1900 = _dateOfBirthEpoch1900;
169169
candidate.gender = _gender;
170170
candidate.presentAddress = _presentAddress;
171171
candidate.email = _email;
@@ -533,13 +533,13 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
533533
* @notice Get details of a specific candidate (publicly accessible)
534534
* @param _candidateAddress Address of the candidate
535535
* @return name The candidate's name
536-
* @return dateOfBirthEpoch The candidate's date of birth as Unix timestamp
536+
* @return dateOfBirthEpoch1900 The candidate's date of birth as Epoch1900 timestamp
537537
* @return gender The candidate's gender
538538
* @return presentAddress The candidate's address
539539
* @return email The candidate's email
540540
* @return qualifications The candidate's qualifications
541541
* @return manifesto The candidate's manifesto
542-
* @return registrationTimestamp When the candidate registered
542+
* @return registrationTimestamp1900 When the candidate registered (Epoch1900)
543543
*/
544544
function getCandidateDetails(
545545
address _candidateAddress
@@ -550,25 +550,25 @@ contract CandidateDatabase is ICandidateDatabase, AdminManagement {
550550
onlyRegistered(_candidateAddress)
551551
returns (
552552
string memory name,
553-
uint256 dateOfBirthEpoch,
553+
uint256 dateOfBirthEpoch1900,
554554
Gender gender,
555555
string memory presentAddress,
556556
string memory email,
557557
string memory qualifications,
558558
string memory manifesto,
559-
uint256 registrationTimestamp
559+
uint256 registrationTimestamp1900
560560
)
561561
{
562562
Candidate memory candidate = s_candidates[_candidateAddress];
563563
return (
564564
candidate.name,
565-
candidate.dateOfBirthEpoch,
565+
candidate.dateOfBirthEpoch1900,
566566
candidate.gender,
567567
candidate.presentAddress,
568568
candidate.email,
569569
candidate.qualifications,
570570
candidate.manifesto,
571-
candidate.registrationTimestamp
571+
candidate.registrationTimestamp1900
572572
);
573573
}
574574

0 commit comments

Comments
 (0)