@@ -15,22 +15,29 @@ contract GenericScheme is UniversalScheme, VotingMachineCallbacks, ProposalExecu
1515 event NewCallProposal (
1616 address indexed _avatar ,
1717 bytes32 indexed _proposalId ,
18- bytes callData
18+ bytes _callData ,
19+ bytes32 _descriptionHash
1920 );
2021
2122 event ProposalExecuted (
2223 address indexed _avatar ,
2324 bytes32 indexed _proposalId ,
24- int256 _param ,
2525 bytes _genericCallReturnValue
2626 );
2727
28+ event ProposalExecutedByVotingMachine (
29+ address indexed _avatar ,
30+ bytes32 indexed _proposalId ,
31+ int256 _param
32+ );
33+
2834 event ProposalDeleted (address indexed _avatar , bytes32 indexed _proposalId );
2935
3036 // Details of a voting proposal:
3137 struct CallProposal {
3238 bytes callData;
3339 bool exist;
40+ bool passed;
3441 }
3542
3643 // A mapping from the organization (Avatar) address to the saved data of the organization:
@@ -48,25 +55,52 @@ contract GenericScheme is UniversalScheme, VotingMachineCallbacks, ProposalExecu
4855 /**
4956 * @dev execution of proposals, can only be called by the voting machine in which the vote is held.
5057 * @param _proposalId the ID of the voting in the voting machine
51- * @param _param a parameter of the voting result, 1 yes and 2 is no.
58+ * @param _decision a parameter of the voting result, 1 yes and 2 is no.
59+ * @return bool success
5260 */
53- function executeProposal (bytes32 _proposalId , int256 _param ) external onlyVotingMachine (_proposalId) returns (bool ) {
61+ function executeProposal (bytes32 _proposalId , int256 _decision )
62+ external
63+ onlyVotingMachine (_proposalId)
64+ returns (bool ) {
65+ Avatar avatar = proposalsInfo[_proposalId].avatar;
66+ CallProposal storage proposal = organizationsProposals[address (avatar)][_proposalId];
67+ require (proposal.exist, "must be a live proposal " );
68+ require (proposal.passed == false , "cannot execute twice " );
69+
70+ if (_decision == 1 ) {
71+ proposal.passed = true ;
72+ execute (_proposalId);
73+ } else {
74+ delete organizationsProposals[address (avatar)][_proposalId];
75+ emit ProposalDeleted (address (avatar), _proposalId);
76+ }
77+
78+ emit ProposalExecutedByVotingMachine (address (avatar), _proposalId, _decision);
79+ return true ;
80+ }
81+
82+ /**
83+ * @dev execution of proposals after it has been decided by the voting machine
84+ * @param _proposalId the ID of the voting in the voting machine
85+ */
86+ function execute (bytes32 _proposalId ) public {
5487 Avatar avatar = proposalsInfo[_proposalId].avatar;
5588 Parameters memory params = parameters[getParametersFromController (avatar)];
56- // Save proposal to memory and delete from storage:
57- CallProposal memory proposal = organizationsProposals[address (avatar)][_proposalId];
89+ CallProposal storage proposal = organizationsProposals[address (avatar)][_proposalId];
5890 require (proposal.exist, "must be a live proposal " );
59- delete organizationsProposals[ address (avatar)][_proposalId] ;
60- emit ProposalDeleted ( address (avatar), _proposalId) ;
91+ require (proposal.passed, " proposal must passed by voting machine " ) ;
92+ proposal.exist = false ;
6193 bytes memory genericCallReturnValue;
62- // Check decision:
63- if (_param == 1 ) {
64- // Define controller and get the params:
65- ControllerInterface controller = ControllerInterface (Avatar (avatar).owner ());
66- genericCallReturnValue = controller.genericCall (params.contractToCall, proposal.callData, avatar);
94+ bool success;
95+ ControllerInterface controller = ControllerInterface (Avatar (avatar).owner ());
96+ (success, genericCallReturnValue) = controller.genericCall (params.contractToCall, proposal.callData, avatar);
97+ if (success) {
98+ delete organizationsProposals[address (avatar)][_proposalId];
99+ emit ProposalDeleted (address (avatar), _proposalId);
100+ emit ProposalExecuted (address (avatar), _proposalId, genericCallReturnValue);
101+ } else {
102+ proposal.exist = true ;
67103 }
68- emit ProposalExecuted (address (avatar), _proposalId, _param, genericCallReturnValue);
69- return true ;
70104 }
71105
72106 /**
@@ -108,9 +142,10 @@ contract GenericScheme is UniversalScheme, VotingMachineCallbacks, ProposalExecu
108142 * The function trigger NewCallProposal event
109143 * @param _callData - The abi encode data for the call
110144 * @param _avatar avatar of the organization
145+ * @param _descriptionHash proposal description hash
111146 * @return an id which represents the proposal
112147 */
113- function proposeCall (Avatar _avatar , bytes memory _callData )
148+ function proposeCall (Avatar _avatar , bytes memory _callData , bytes32 _descriptionHash )
114149 public
115150 returns (bytes32 )
116151 {
@@ -121,14 +156,15 @@ contract GenericScheme is UniversalScheme, VotingMachineCallbacks, ProposalExecu
121156
122157 organizationsProposals[address (_avatar)][proposalId] = CallProposal ({
123158 callData: _callData,
124- exist: true
159+ exist: true ,
160+ passed: false
125161 });
126162 proposalsInfo[proposalId] = ProposalInfo ({
127163 blockNumber:block .number ,
128164 avatar:_avatar,
129165 votingMachine:address (params.intVote)
130166 });
131- emit NewCallProposal (address (_avatar), proposalId, _callData);
167+ emit NewCallProposal (address (_avatar), proposalId, _callData, _descriptionHash );
132168 return proposalId;
133169 }
134170
0 commit comments