deploy遇到问题,查了google也没解决

代码如下:

pragma solidity ^0.4.18;
contract Voting {
    //xiaop  14
    //lih   10
    //luoh   13
    //wangjq  15
    //wangy    17
    //["xiaop","lih","luoh","wangjq","wangy"]
    bytes32[] candidates = new bytes32[](5);
    mapping(bytes32 => uint) candidatesVotingCount;
    
    function Voting(bytes32[] _candidates) public {
        for (uint i=0;i<_candidates.length;i++) {
            candidates[i] = _candidates[i];
        }
    }
    
    function isValidCandidate(bytes32 person) constant public returns (bool) {

        for(uint i=0;i<candidates.length;i++) {
            //bytes storage a = bytes(candidates[i]);//*****
          if (candidates[i]==person) {
          
          return true;
          }
        }
        
    }
    
    function VotingToPerson(bytes32 person) public {
        assert(isValidCandidate(person));//判断zhen jia真假 
        //require(isValidCandidate(person));//功能同上 
        candidatesVotingCount[person] += 1;
        
    }
    
    function VotingTotalToPerson(bytes32 person) constant public returns (uint) {
        require(isValidCandidate(person));
        return candidatesVotingCount[person];
    }

deploy后提示creation of Voting errored: Error encoding arguments: Error: invalid bytes32 value (arg="", type="string", value="xiaop")

google后两种解决方案

1、将bytes32转码成16进制如"xiaop"转成"0x7869616f70",但是又遇到

creation of Voting errored: Error encoding arguments: Error: hex string cannot be odd-length //字符串长度不一致问题,只能输入同样长度的16进制数。deploy成功

2、将bytes32用string代替,没有去实现,继续上课中,有时间再来尝试

猜你喜欢

转载自blog.csdn.net/qq_41390321/article/details/83480019