-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitterV1.sol
109 lines (97 loc) · 2.74 KB
/
TwitterV1.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Voting {
//━━━━━━━━━━━━━initialization━━━━━━━━━━━━━━━━━━//
struct Candidate {
uint256 id;
string name;
string party;
string gender;
uint256 age;
address Address;
}
struct Voter {
uint256 id;
string name;
string gender;
uint256 age;
address Address;
}
mapping(uint256 => Candidate) public candidateDetails;
mapping(uint256 => Voter) public VoterDetails;
uint256 candidateId = 1;
uint256 VoterId = 1;
//━━━━━━━━━━━━━functions━━━━━━━━━━━━━━━━━━//
function CandidateRegister(
string calldata _name,
string calldata _party,
string calldata _gender,
uint256 _age
) public {
require(
CandidateVerification(msg.sender),
"Candidate account is already exist !!"
);
candidateDetails[candidateId] = Candidate(
candidateId,
_name,
_party,
_gender,
_age,
msg.sender
);
candidateId += 1;
}
function CandidateVerification(address _sender)
private
view
returns (bool)
{
for (uint256 i = 0; i < candidateId; i++) {
if (candidateDetails[i].Address == _sender) {
return false;
}
}
return true;
}
function CandidateList() public view returns (Candidate[] memory) {
Candidate[] memory array = new Candidate[](candidateId - 1);
for (uint256 i = 1; i < candidateId; i++) {
array[i - 1] = candidateDetails[i];
}
return array;
}
function VoterRegister(
string calldata _name,
string calldata _gender,
uint256 _age
) public {
require(
VoterVerification(msg.sender),
"Voter account is already register"
);
VoterDetails[VoterId] = Voter(
VoterId,
_name,
_gender,
_age,
msg.sender
);
VoterId += 1;
}
function VoterVerification(address _sender) private view returns (bool) {
for (uint256 i = 1; i < VoterId; i++) {
if (VoterDetails[i].Address == _sender) {
return false;
}
}
return true;
}
function VoterList() public view returns (Voter[] memory) {
Voter[] memory array = new Voter[](VoterId - 1);
for (uint256 i = 1; i < VoterId; i++) {
array[i - 1] = VoterDetails[i];
}
return array;
}
}