Вопрос:

Ошибка при развертывании смарт-контракта для Azure Blockchain Workbench

azure blockchain solidity smartcontracts azure-blockchain-workbench

16 просмотра

1 ответ

18 Репутация автора

Я создавал приложение для голосования в Azure Blockchain Workbench. Я постоянно получаю ошибки при загрузке файла смарт-контракта, что конструктор и функции отсутствуют. Хотя файл конфигурации прошел их проверки. Пожалуйста, помогите с ошибкой.

Это из файла смарт-контракта:

pragma solidity >= 0.4.0 <0.6.0;

contract Voting{
    enum StateType{
      Creation,
      Voting,
      BallotFinish
    }
    StateType public State;
    mapping(bytes32 => uint256) public votesCount;
    address public admin;
    bytes32[] public candidatesList;
    bytes32[] public voterList;
    constructor(bytes32[] memory candidateNames,bytes32[] memory voterNames) public{
        State = StateType.Creation;
        admin = msg.sender;
        candidatesList = candidateNames;
        voterList = voterNames;
    }
    function totalVotesFor(bytes32 candidate) public view returns (uint256)
    {
        require(validCandidate(candidate));
        return votesCount[candidate];
    }
    function voteForCandidate(bytes32 voter,bytes32 candidate) public {
        if(admin == msg.sender)
        {
            revert();
        }
        if(State == StateType.Voting)
        {
            require(validVoter(voter));
            require(validCandidate(candidate));
            votesCount[candidate] += 1;
        }
        else
        {
            revert();
        }
    }
    function validVoter(bytes32 voter) public view returns (bool) {
        for(uint i=0;i<voterList.length;i++)
        {
            if(voterList[i]==voter)
                return true;
        }
        return false;
    }
    function validCandidate(bytes32 candidate) public view returns (bool) {
        for(uint i=0 ; i < candidatesList.length ; i++)
        {
            if(candidatesList[i]==candidate)
                return true;
        }
        return false;
    }
}

Это файл конфигурации:

{
    "ApplicationName": "Voting",
    "DisplayName": "Voting",
    "Description": "Test Voting App",
    "ApplicationRoles": [
      {
        "Name": "Admin",
        "Description": "Person who generates Candidate and Voter Lists"
      },
      {
        "Name": "Voter",
        "Description": "A person who votes"
      }
    ],
    "Workflows": [
      {
        "Name": "Voting",
        "DisplayName": "Vote Here",
        "Description": "A simple way to vote.",
        "Initiators": [ "Admin" ],
        "StartState": "Creation",
        "Properties": [
          {
            "Name": "State",
            "DisplayName": "State",
            "Description": "Holds the state of the contract.",
            "Type": {
              "Name": "state"
            }
          }
        ],
        "Constructor": {
          "Parameters": [
            {
              "Name": "candidateNames",
              "Description": "List of names of candidates",
              "DisplayName": "ListOfCandidates",
              "Type":
              {
                  "Name": "array",
                  "ElementType": {
                      "Name": "string"
                  }
              }
            },
            {
              "Name": "voterNames",
              "Description": "List of names of voters",
              "DisplayName": "ListOfVoters",
              "Type":{
                "Name": "array",
                "ElementType": {
                  "Name": "string"
                }
              }
            }
          ]
        },
        "Functions": [
          {
            "Name": "totalVotesFor",
            "DisplayName": "Get Votes for a Candidate",
            "Description": "...",
            "Parameters": [
              {
                "Name": "candidate",
                "Description": "...",
                "DisplayName": "Name of Candidate",
                "Type": {
                  "Name": "string"
                }
              }
            ]
          },
          {
            "Name": "voteForCandidate",
            "DisplayName": "Vote Function",
            "Description": "...",
            "Parameters": [
              {
                "Name": "voter",
                "Description": "...",
                "DisplayName": "Name of Voter",
                "Type": {
                  "Name": "string"
                }
              },
              {
                "Name": "candidate",
                "Description": "...",
                "DisplayName": "Name of Candidate",
                "Type": {
                  "Name": "string"
                }
              }
            ]
          }
        ],
        "States": [
          {
            "Name": "Creation",
            "DisplayName": "Ballot Creation",
            "Description": "...",
            "PercentComplete": 20,
            "Style": "Success",
            "Transitions": [
              {
                "AllowedRoles": ["Voter"],
                "AllowedInstanceRoles": [],
                "Description": "...",
                "Function": "voteForCandidate",
                "NextStates": [ "Voting" ],
                "DisplayName": "Give Vote"
              },
              {
                "AllowedRoles": ["Voter"],
                "AllowedInstanceRoles": [],
                "Description": "...",
                "Function": "totalVotesFor",
                "NextStates": [ "Voting" ],
                "DisplayName": "Get No of Votes"
              }
            ]
          },
          {
            "Name": "Voting",
            "DisplayName": "Voting Stage",
            "Description": "...",
            "PercentComplete": 20,
            "Style": "Success",
            "Transitions": [
              {
                "AllowedRoles": ["Voter"],
                "AllowedInstanceRoles": [],
                "Description": "...",
                "Function": "totalVotesFor",
                "NextStates": [ "Voting" ],
                "DisplayName": "Vote for a Candidate"
              }
            ]
          },
          {
            "Name": "BallotFinish",
            "DisplayName": "Voting Finished",
            "Description": "...",
            "PercentComplete": 100,
            "Style": "Success",
            "Transitions": []
          }
        ]
      }
    ]
  }

Скриншот сообщения об ошибке

Автор: Hardik Mehta Источник Размещён: 05.08.2019 08:14

Ответы (1)


0 плюса

64 Репутация автора

Ваш файл sol должен иметь конструктор для контракта, как указано в файле json.

Я думаю, что вам нужно изменить byte32 на строку и использовать StringUtil для сравнения строк

Автор: Shobhit Kumar Размещён: 11.08.2019 06:59
Вопросы из категории :
32x32