I have been Building a Voting App on Azure Blockchain Workbench. I am constantly getting errors while uploading the smart contract file that the constructor and the functions are not present.The config file passed their checks though. Pls help out with the error.
This is from the Smart contract file:
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;
}
}
This is the config file:
{
"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": []
}
]
}
]
}
Your sol file needs to have a constructor for the contract as specified in the json file.
I think you need to change the byte32 to string and use StringUtil for comparision of strings