pragma solidity ^0.4.23; contract DaicoVote { ... // Constructor IDaicoToken public tokenContract; // Token contract interface uint256 public endTime; uint256 public cumulativeYes; uint256 public cumulativeNo; mapping(address => voteInstance) public voteByAddress; // Stores the individual votes struct voteInstance { uint256 time; uint256 weight; bool vote; } function tallyResult() public view returns (bool) { uint256 abstain = (tokenContract.totalSupply().add(cumulativeNo)).sub(cumulativeYes); return (cumulativeYes > cumulativeNo.add(calcAbstain())) ? true : false; } function finalResult() public view returns (bool) { require(now > endTime); return tallyResult(); } // Record token holder balance in cumulative vote function submitVote(bool _vote) public returns (bool) { ... // require positive token balance, active voting period and no previous vote for this address // Get token holder balance uint256 voteWeight = tokenContract.balanceOf(msg.sender); // Record vote instance voteByAddress[msg.sender].time = now; voteByAddress[msg.sender].weight = voteWeight; voteByAddress[msg.sender].vote = _vote; // Add vote to appropriate totals if (_vote == true) { cumulativeYes = cumulativeYes.add(voteWeight); } if (_vote == false) { cumulativeNo = cumulativeNo.add(voteWeight); } return true; } function callOnTransfer(address _sender, address _receiver, uint256 _amount) public returns (bool) { ... // Only callable from tapContract // Get weights of exisitng votes uint256 senderVote = voteByAddress[_sender].weight; uint256 receiverVote = voteByAddress[_receiver].weight; // Rebalance votes for sender and receiver if (senderVote > 0) { voteByAddress[_sender].weight = senderVote.sub(_amount); _weightDecrease(_sender,_amount); if (receiverVote > 0) { voteByAddress[_receiver].weight = receiverVote.add(_amount); _weightIncrease(_receiver,_amount); } } return true; } // Adjust cumulative totals function _weightDecrease(address _tokenholder, uint256 _amount) private { bool vote = voteByAddress[_tokenholder].vote; if (vote == true) { cumulativeYes = cumulativeYes.sub(_amount); } if (vote == false) { cumulativeNo = cumulativeNo.sub(_amount); } } // Adjust cumulative totals function _weightIncrease(address _tokenholder, uint256 _amount) private { bool vote = voteByAddress[_tokenholder].vote; if (vote == true) { cumulativeYes = cumulativeYes.add(_amount); } if (vote == false) { cumulativeNo = cumulativeNo.add(_amount); } } }
0.5.4