-
Notifications
You must be signed in to change notification settings - Fork 0
/
CandidateRegistry.sol
34 lines (28 loc) · 1.06 KB
/
CandidateRegistry.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.2;
import "./ElectionManager.sol";
contract CandidateRegistry is ElectionManager {
struct Candidate {
uint256 id;
string name;
string description;
string imageIPFSHash;
uint256 voteCount;
}
Candidate[] public candidates;
function registerCandidate(string memory name, string memory description, string memory imageIPFSHash) public onlyOwner {
// Register candidate with its information and reference to IPFS
candidates.push(Candidate({
id: candidates.length,
name: name,
description: description,
imageIPFSHash: imageIPFSHash,
voteCount: 0
}));
}
function getCandidate(uint256 candidateId) public view returns (string memory, string memory, string memory, uint256) {
require(candidateId < candidates.length, "Invalid candidate.");
Candidate memory c = candidates[candidateId];
return (c.name, c.description, c.imageIPFSHash, c.voteCount);
}
}