Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/contracts/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ contract VotingForPurpose{
electionCount++;
elections[electionCount]=Election(electionCount,_purpose,1,new uint[](0),0);
}

function addCandidate(string memory _name, string memory _details, uint _election_id) public ownerOn {
require(_election_id<=electionCount && uint(elections[_election_id].status)==1,"Election is not created");
candidatesCount++;
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0, _details, _election_id);
elections[_election_id].candidatesids.push(candidatesCount);
}

function addVoter(address _voteraddress,string memory _votername)
public {
require(msg.sender != owner,"Only voter can register himself");
require(bytes(voters[msg.sender].votername).length==0,"Voter already added");
voters[_voteraddress]=Voter(_votername,false);
voterslist.push(_voteraddress);
totalregisteredvoters++;
}
}
41 changes: 41 additions & 0 deletions src/utils/election.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,47 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "string",
"name": "_details",
"type": "string"
},
{
"internalType": "uint256",
"name": "_election_id",
"type": "uint256"
}
],
"name": "addCandidate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_voteraddress",
"type": "address"
},
{
"internalType": "string",
"name": "_votername",
"type": "string"
}
],
"name": "addVoter",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Loading