我试图将一个bytes32推到一个数组中,但是它仍然是空的。
这是我代码的一部分:
contract Voting {
bytes32[] public encryptedVotes;
bytes32[] public candidateList;
address[] public pollingStationList;
address public owner;
function Voting(bytes32[] _candidateList, address[] _pollingStationList) public {
candidateList = _candidateList;
pollingStationList = _pollingStationList;
owner = msg.sender;
}
function vote(bytes32 encryptedVote) public {
encryptedVotes.push(encryptedVote);
}
function getEncryptedVotes() view public returns (bytes32[]) {
return encryptedVotes;
}
}不要介意代码的“加密”部分,它是更多逻辑的一部分。
问题在于“投票”的功能。当我用web3调用它"contractInstance.vote.call("a值“)”时,它返回[],但不改变状态。调用getEncryptedVotes返回[]。
我没有看到围绕bytes32的一些逻辑吗?提前感谢!
发布于 2018-01-23 18:24:34
你的问题在于你怎么称呼它。使用契约函数的".call“不会创建事务,它将对该函数执行只读调用。这用于常量/视图函数。因此,当您调用contractInstance.vote.call("a value")时,它将从链上运行该函数,而不会更新状态。您应该能够只调用constractInstance.vote("a value"),它实际上将更新契约的状态。
https://ethereum.stackexchange.com/questions/37256
复制相似问题