1. 程式人生 > >deploy遇到問題,查了google也沒解決

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代替,沒有去實現,繼續上課中,有時間再來嘗試