From 0423ce678176079fc18960686e49524e43d546d3 Mon Sep 17 00:00:00 2001 From: Rostyslav Bortman Date: Tue, 24 Jul 2018 14:38:28 +0300 Subject: [PATCH] Improve StdDaoToken - startVoting/endVoting through the DaoBase #210 --- contracts/governance/Voting.sol | 15 +++++++++++---- contracts/tokens/StdDaoToken.sol | 11 +++++++++-- contracts/utils/GenericCaller.sol | 7 ++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/contracts/governance/Voting.sol b/contracts/governance/Voting.sol index c004dcf..fa4295b 100644 --- a/contracts/governance/Voting.sol +++ b/contracts/governance/Voting.sol @@ -39,6 +39,13 @@ contract Voting is IVoting, Ownable { store.generalConstructor(_dao, _proposal, _origin, _votingType, _minutesToVote, _groupName, _quorumPercent, _consensusPercent, _tokenAddress); } + function setStdDaoTokenVotingID(uint _stdDaoTokenVotingID) public onlyOwner { + if(VotingType.Voting1p1v!=store.votingType){ + store.votingID = _stdDaoTokenVotingID; + } + } + + function quorumPercent()view returns(uint){ return store.quorumPercent; } @@ -61,6 +68,9 @@ contract Voting is IVoting, Ownable { function vote(bool _isYes) public{ store.libVote(msg.sender, _isYes); + if(store.isFinished(store)){ + StdDaoToken(store.tokenAddress).finishVoting(store.votingID); + } } function callActionIfEnded() public { @@ -164,11 +174,8 @@ library VotingLib { store.groupName = _groupName; store.votingType = _votingType; store.genesis = now; + store.tokenAddress = _tokenAddress; - if(VotingType.Voting1p1v!=store.votingType){ - store.tokenAddress = _tokenAddress; - store.votingID = StdDaoToken(_tokenAddress).startNewVoting(); - } libVote(store, _origin, true); } diff --git a/contracts/tokens/StdDaoToken.sol b/contracts/tokens/StdDaoToken.sol index 3858b0c..c1ecbc8 100644 --- a/contracts/tokens/StdDaoToken.sol +++ b/contracts/tokens/StdDaoToken.sol @@ -5,6 +5,7 @@ import "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol"; import "./CopyOnWriteToken.sol"; import "./ITokenVotingSupport.sol"; +import "../DaoBase.sol"; /** * @title StdDaoToken @@ -24,13 +25,16 @@ import "./ITokenVotingSupport.sol"; * finishVoting() * getBalanceAtVoting() */ -contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVotingSupport { +contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, DaoBase, ITokenVotingSupport { uint256 public cap; bool isBurnable; bool isPausable; address[] public holders; mapping (address => bool) isHolder; + mapping (uint => address) votingCreated; + + bytes32 public TOKEN_StartNewVoting = keccak256(abi.encodePacked("TOKEN_StartNewVoting")); modifier isBurnable_() { require (isBurnable); @@ -58,14 +62,17 @@ contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVo // ITokenVotingSupport implementation // TODO: VULNERABILITY! no onlyOwner! - function startNewVoting() public whenNotPaused returns(uint) { + function startNewVoting(address _voting) public whenNotPaused isCanDo(TOKEN_StartNewVoting) returns(uint) { uint idOut = super.startNewEvent(); + votingCreated[idOut] = _voting; emit VotingStarted(msg.sender, idOut); return idOut; } // TODO: VULNERABILITY! no onlyOwner! function finishVoting(uint _votingID) whenNotPaused public { + require (msg.sender == votingCreated[_votingID]); + super.finishEvent(_votingID); emit VotingFinished(msg.sender, _votingID); } diff --git a/contracts/utils/GenericCaller.sol b/contracts/utils/GenericCaller.sol index 690e622..958aa30 100644 --- a/contracts/utils/GenericCaller.sol +++ b/contracts/utils/GenericCaller.sol @@ -114,15 +114,20 @@ contract GenericCaller is DaoClient, Ownable { function createVoting(bytes32 _permissionIdHash, IProposal _proposal, address _origin)public returns(IVoting){ VotingParams memory vp = votingParams[_permissionIdHash]; + StdDaoToken memory token = StdDaoToken(address(vp.param5)); IVoting V = new Voting(dao, _proposal, _origin, vp.votingType, uint(vp.param1), bytes32ToString(vp.param2), uint(vp.param3), uint(vp.param4), - address(vp.param5) + address(vp.param5), + stdDaoTokenVotingID ); + uint stdDaoTokenVotingID = token.startNewVoting(V.address); + V.setStdDaoTokenVotingID(stdDaoTokenVotingID); + return V; }