我有一个用Solidity编写的智能合约。我在用户按下按钮时触发事件。允许用户仅按一次该按钮。我的问题是,由于要更改帐户并能够再次按该按钮而重新加载页面时,该事件仍在触发,尽管我没有按下它,并且每次重新加载时总是触发该事件这一页。知道如何解决这个问题吗?
这是我的活动:
listenForEvents: function(){
App.contracts.Election.deployed().then(function(instance){
instance.votedEvent({}, {
fromBlock: 'latest',
}).watch(function(err, event){
console.log("event triggered", event);
App.render();
});
});
},
这是用户按下按钮并触发事件时执行的功能:
function vote(uint _candidateId) public {
require(!voters[msg.sender]);
require(_candidateId > 0 && _candidateId <= candidatesCount);
voters[msg.sender] = true;
candidates[_candidateId].voteCount ++;
emit votedEvent(_candidateId);
}