如何解决选民如何确认候选人的选择没有改变?
When the electoral process is over,how can the Voter verify that the candidate’s choice has not changed? 我想在合同中添加一个函数,但是我不知道如何构造这个函数 I want an example when the Voter puts his address,the system returns the name of the candidate who has been chosen since the election process. 我需要智能合约中的一个函数来做到这一点
pragma solidity ^0.6.0;
contract Voting {
// Model a Candidate
struct Candidate {
uint256 id;
string name;
uint256 VoteCount;
}
mapping(address => bool) public Voters;
mapping(uint256 => Candidate) public candidates;
// Store Candidates count
uint256 public candidatesCount;
// Voted event
event VotedEvent(uint256 indexed _candidateId);
constructor() public {
addCandidate("Candidate #1");
addCandidate("Candidate #2");
addCandidate("Candidate #3");
}
function addCandidate(string memory _name) private {
candidatesCount++;
candidates[candidatesCount] = Candidate(candidatesCount,_name,0);
}
function Vote(uint256 _candidateId) public {
// require that they haven't Voted before
require(!Voters[msg.sender]);
// require a valid candidate
require(_candidateId > 0 && _candidateId <= candidatesCount);
// record that Voter has Voted
Voters[msg.sender] = true;
// update candidate Vote Count
candidates[_candidateId].VoteCount++;
// trigger Voted event
emit VotedEvent(_candidateId);
}
function getCondidateName(address adr) pure public returns( string memory ){
// here i need to create thecode of the verify }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。