democracy , constitution and factory refactor

This commit is contained in:
Ricardo Guilherme Schmidt 2018-03-27 23:16:51 -03:00
parent 1544368968
commit ed798f4a91
7 changed files with 109 additions and 107 deletions

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.17; pragma solidity ^0.4.21;
import "../common/Controlled.sol"; import "../common/Controlled.sol";
import "../token/ERC20Token.sol"; import "../token/ERC20Token.sol";

View File

@ -1,5 +0,0 @@
pragma solidity ^0.4.17;
contract ProposalExecutor {
function executeProposal(address topic, uint value, bytes data) external returns (bool success);
}

View File

@ -1,58 +1,18 @@
pragma solidity ^0.4.17; pragma solidity ^0.4.21;
import "./ProposalManagerInterface.sol";
import "./TrustNetworkInterface.sol"; import "./TrustNetworkInterface.sol";
import "./DelegationProxyInterface.sol"; import "./DelegationProxyInterface.sol";
import "../token/MiniMeTokenInterface.sol"; import "../token/MiniMeTokenInterface.sol";
import "../common/Controlled.sol"; import "../common/Controlled.sol";
import "./ProposalExecutor.sol";
/** /**
* @title ProposalManager * @title ProposalManager
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* Store the proposals, votes and results for other smartcontracts * Store the proposals, votes and results for other smartcontracts
*/ */
contract ProposalManager is Controlled { contract ProposalManager is ProposalManagerInterface, Controlled {
TrustNetworkInterface public trustNet;
MiniMeTokenInterface public token;
uint256 public tabulationBlockDelay = 10000;
Proposal[] proposals;
struct Proposal {
bytes32 topic;
bytes32 txHash;
uint stake;
address staker;
uint blockStart;
uint voteBlockEnd;
uint vetoBlockEnd;
mapping(address => Vote) voteMap;
mapping(address => Tabulations) tabulated;
mapping(uint8 => uint256) results;
bool approved;
bool executed;
}
struct Tabulations {
bool vote;
bool veto;
}
enum Vote {
Null,
Reject,
Approve,
Veto
}
function ProposalManager(MiniMeTokenInterface _SNT, TrustNetworkInterface _trustNet) public { function ProposalManager(MiniMeTokenInterface _SNT, TrustNetworkInterface _trustNet) public {
trustNet = _trustNet; trustNet = _trustNet;
token = _SNT; token = _SNT;
@ -85,14 +45,6 @@ contract ProposalManager is Controlled {
return proposals[id].txHash; return proposals[id].txHash;
} }
function execute(uint id, address dest, uint value, bytes data) public {
Proposal memory p = proposals[id];
require(p.approved == true);
require(keccak256(dest, value, data) == p.txHash);
proposals[id].executed = true;
ProposalExecutor(controller).executeProposal(dest, value, data);
}
function vote(uint _proposal, Vote _vote) public { function vote(uint _proposal, Vote _vote) public {
Proposal storage proposal = proposals[_proposal]; Proposal storage proposal = proposals[_proposal];
require(block.number >= proposal.blockStart); require(block.number >= proposal.blockStart);
@ -106,17 +58,14 @@ contract ProposalManager is Controlled {
} }
function tabulateVote(uint _proposal, address _delegator) public { function tabulateVote(uint _proposal, address _delegator) public {
Proposal storage proposal = proposals[_proposal]; Proposal storage proposal = proposals[_proposal];
require(block.number > proposal.voteBlockEnd); require(block.number > proposal.voteBlockEnd);
require(!proposal.tabulated[_delegator].vote); require(!proposal.tabulated[_delegator].vote);
proposal.tabulated[_delegator].vote = true; proposal.tabulated[_delegator].vote = true;
Vote _vote = proposal.voteMap[_delegator]; Vote _vote = proposal.voteMap[_delegator];
if(_vote == Vote.Null) { if(_vote == Vote.Null) {
DelegationProxyInterface voteDelegation; address delegate = trustNet.getVoteDelegation(proposal.topic).delegationOfAt(_delegator, proposal.vetoBlockEnd);
DelegationProxyInterface vetoDelegation;
(voteDelegation, vetoDelegation) = trustNet.getTopic(proposal.topic);
address delegate = voteDelegation.delegationOfAt(_delegator, proposal.vetoBlockEnd);
_vote = proposal.voteMap[delegate]; _vote = proposal.voteMap[delegate];
} }
@ -132,10 +81,7 @@ contract ProposalManager is Controlled {
proposal.tabulated[_delegator].veto = true; proposal.tabulated[_delegator].veto = true;
Vote _vote = proposal.voteMap[_delegator]; Vote _vote = proposal.voteMap[_delegator];
if (_vote == Vote.Null) { if (_vote == Vote.Null) {
DelegationProxyInterface voteDelegation; address delegate = trustNet.getVetoDelegation(proposal.topic).delegationOfAt(_delegator, proposal.vetoBlockEnd);
DelegationProxyInterface vetoDelegation;
(voteDelegation, vetoDelegation) = trustNet.getTopic(proposal.topic);
address delegate = vetoDelegation.delegationOfAt(_delegator, proposal.vetoBlockEnd);
_vote = proposal.voteMap[delegate]; _vote = proposal.voteMap[delegate];
} }
@ -159,4 +105,11 @@ contract ProposalManager is Controlled {
proposal.approved = true; proposal.approved = true;
require(token.transferFrom(address(this), proposal.staker, proposal.stake)); require(token.transferFrom(address(this), proposal.staker, proposal.stake));
} }
function setExecuted(uint id) public onlyController {
Proposal memory p = proposals[id];
require(p.approved);
require(!p.executed);
proposals[id].executed = true;
}
} }

View File

@ -0,0 +1,59 @@
pragma solidity ^0.4.21;
import "./TrustNetworkInterface.sol";
import "./DelegationProxyInterface.sol";
import "../token/MiniMeTokenInterface.sol";
/**
* @title ProposalManager
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* Store the proposals, votes and results for other smartcontracts
*/
contract ProposalManagerInterface {
TrustNetworkInterface public trustNet;
MiniMeTokenInterface public token;
uint256 public tabulationBlockDelay;
Proposal[] public proposals;
struct Proposal {
bytes32 topic;
bytes32 txHash;
uint stake;
address staker;
uint blockStart;
uint voteBlockEnd;
uint vetoBlockEnd;
mapping(address => Vote) voteMap;
mapping(address => Tabulations) tabulated;
mapping(uint8 => uint256) results;
bool approved;
bool executed;
}
struct Tabulations {
bool vote;
bool veto;
}
enum Vote {
Null,
Reject,
Approve,
Veto
}
function addProposal(bytes32 _topic, bytes32 _txHash, uint _stake) public returns (uint);
function getProposal(uint id) public constant returns (bytes32 topic, bytes32 txHash, uint stake, address staker, bool approved, bool executed);
function getProposalTxHash(uint id) public constant returns(bytes32);
function vote(uint _proposal, Vote _vote) public;
function tabulateVote(uint _proposal, address _delegator) public;
function tabulateVeto(uint _proposal, address _delegator) public;
function approve(uint _proposal) public;
function setExecuted(uint id) public;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.10; pragma solidity ^0.4.21;
import "../common/Controlled.sol"; import "../common/Controlled.sol";
import "./TrustNetworkInterface.sol"; import "./TrustNetworkInterface.sol";
@ -16,8 +16,8 @@ contract TrustNetwork is TrustNetworkInterface, Controlled {
DelegationProxyFactory delegationFactory; DelegationProxyFactory delegationFactory;
struct Topic { struct Topic {
DelegationProxy voteProxy; DelegationProxy voteDelegation;
DelegationProxy vetoProxy; DelegationProxy vetoDelegation;
} }
function TrustNetwork(address _delegationFactory) public { function TrustNetwork(address _delegationFactory) public {
@ -27,29 +27,49 @@ contract TrustNetwork is TrustNetworkInterface, Controlled {
function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController { function addTopic(bytes32 topicId, bytes32 parentTopic) public onlyController {
Topic memory parent = topics[parentTopic]; Topic memory parent = topics[parentTopic];
address vote = address(parent.voteProxy); address vote = address(parent.voteDelegation);
address veto = address(parent.vetoProxy); address veto = address(parent.vetoDelegation);
require(vote != 0x0); require(vote != 0x0);
require(veto != 0x0); require(veto != 0x0);
Topic storage topic = topics[topicId]; Topic storage topic = topics[topicId];
require(address(topic.voteProxy) == 0x0); require(address(topic.voteDelegation) == 0x0);
require(address(topic.vetoProxy) == 0x0); require(address(topic.vetoDelegation) == 0x0);
topics[topicId] = newTopic(vote, veto); topics[topicId] = newTopic(vote, veto);
} }
function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto) { function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto) {
Topic memory topic = topics[_topicId]; Topic memory topic = topics[_topicId];
vote = topic.voteProxy; vote = topic.voteDelegation;
veto = topic.vetoProxy; veto = topic.vetoDelegation;
} }
function getVoteDelegation(
bytes32 _topicId
)
public
view
returns (DelegationProxyInterface voteDelegation)
{
return topics[_topicId].voteDelegation;
}
function getVetoDelegation(
bytes32 _topicId
)
public
view
returns (DelegationProxyInterface vetoDelegation)
{
return topics[_topicId].vetoDelegation;
}
function newTopic(address _vote, address _veto) internal returns (Topic topic) { function newTopic(address _vote, address _veto) internal returns (Topic topic) {
topic = Topic ({ topic = Topic ({
voteProxy: delegationFactory.create(_vote), voteDelegation: delegationFactory.createDelegationProxy(_vote),
vetoProxy: delegationFactory.create(_veto) vetoDelegation: delegationFactory.createDelegationProxy(_veto)
}); });
} }

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.17; pragma solidity ^0.4.21;
import "./DelegationProxyInterface.sol"; import "./DelegationProxyInterface.sol";
@ -6,5 +6,6 @@ contract TrustNetworkInterface {
function addTopic(bytes32 topicId, bytes32 parentTopic) public; function addTopic(bytes32 topicId, bytes32 parentTopic) public;
function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto); function getTopic(bytes32 _topicId) public constant returns (DelegationProxyInterface vote, DelegationProxyInterface veto);
function getVoteDelegation(bytes32 _topicId) public view returns (DelegationProxyInterface voteDelegation);
function getVetoDelegation(bytes32 _topicId) public view returns (DelegationProxyInterface vetoDelegation);
} }

View File

@ -1,26 +0,0 @@
pragma solidity ^0.4.10;
import "./TrustNetwork.sol";
import "../deploy/KillableModel.sol";
/**
* @title TrustNetworkModel
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* Model for TrustNetwork
*/
contract TrustNetworkModel is KillableModel, TrustNetwork {
function TrustNetworkModel(address _watchdog) KillableModel(_watchdog) TrustNetwork(0x0) public {
}
function create(address _delegationFactory) public {
require(topics[0x0].voteProxy == address(0x0));
delegationFactory = DelegationProxyFactory(_delegationFactory);
topics[0x0] = newTopic(0x0, 0x0);
}
}