以太坊之dapp

此处是上篇文中的完整以太坊智能合约
pragma solidity >=0.4.22<0.8.0;
contract Voting{

bytes32[] public candidateList;
mapping(bytes32 => uint8) public votesRece;
constructor(bytes32[] memory candidateListName) public{
    candidateList = candidateListName;
}

//检查候选人

function hefacandidate(bytes32 candidateName) internal view returns (bool){
    for(uint8 i =0;i<candidateList.length;i++){
        if(candidateName ==candidateList[i]){
            return true;
        }
    }
    return false;
}

function voteForCandidate (bytes32 candidateName)public{
    require (hefacandidate(candidateName));
    votesRece[candidateName] +=1;
}
function LookForCandidate (bytes32 candidateName) view public returns(uint8){
    require (hefacandidate(candidateName));
    return votesRece[candidateName];
}

}

上一篇:ArcEngine数据编辑--选择要素


下一篇:Java高级——缓存的使用场景