gpt4 book ai didi

azure - 为 Azure Blockchain Workbench 部署智能合约时出错

转载 作者:行者123 更新时间:2023-12-02 07:05:07 25 4
gpt4 key购买 nike

我一直在 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": []
}
]
}
]
}

Screenshot of the error message

最佳答案

您的 sol 文件需要具有 json 文件中指定的合约构造函数。

我认为你需要将 byte32 更改为字符串并使用 StringUtil 进行字符串比较

关于azure - 为 Azure Blockchain Workbench 部署智能合约时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57354628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com