topic add stake and custom factory
This commit is contained in:
parent
da6dc213d3
commit
91361db682
|
@ -10,6 +10,8 @@ contract Democracy {
|
||||||
struct Topic {
|
struct Topic {
|
||||||
bytes32 parent;
|
bytes32 parent;
|
||||||
Delegation delegation;
|
Delegation delegation;
|
||||||
|
ProposalFactory proposalFactory;
|
||||||
|
uint256 stakeValue;
|
||||||
Proposal.QuorumType quorum;
|
Proposal.QuorumType quorum;
|
||||||
uint256 startBlockDelay;
|
uint256 startBlockDelay;
|
||||||
uint256 votingBlockDelay;
|
uint256 votingBlockDelay;
|
||||||
|
@ -18,6 +20,8 @@ contract Democracy {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProposalData {
|
struct ProposalData {
|
||||||
|
address proponent;
|
||||||
|
uint256 lockedStake;
|
||||||
bytes32 topic;
|
bytes32 topic;
|
||||||
address destination;
|
address destination;
|
||||||
bytes data;
|
bytes data;
|
||||||
|
@ -25,7 +29,7 @@ contract Democracy {
|
||||||
|
|
||||||
MiniMeToken public token;
|
MiniMeToken public token;
|
||||||
DelegationFactory public delegationFactory;
|
DelegationFactory public delegationFactory;
|
||||||
ProposalFactory public proposalFactory;
|
|
||||||
|
|
||||||
mapping (bytes32 => Topic) topics;
|
mapping (bytes32 => Topic) topics;
|
||||||
mapping (address => ProposalData) proposals;
|
mapping (address => ProposalData) proposals;
|
||||||
|
@ -40,6 +44,7 @@ contract Democracy {
|
||||||
DelegationFactory _delegationFactory,
|
DelegationFactory _delegationFactory,
|
||||||
ProposalFactory _proposalFactory,
|
ProposalFactory _proposalFactory,
|
||||||
Delegation _parentDelegation,
|
Delegation _parentDelegation,
|
||||||
|
uint256 _stakeValue,
|
||||||
Proposal.QuorumType _quorumType,
|
Proposal.QuorumType _quorumType,
|
||||||
uint256 startBlockDelay,
|
uint256 startBlockDelay,
|
||||||
uint256 votingBlockDelay,
|
uint256 votingBlockDelay,
|
||||||
|
@ -54,6 +59,8 @@ contract Democracy {
|
||||||
topics[bytes32(0)] = Topic(
|
topics[bytes32(0)] = Topic(
|
||||||
bytes32(0),
|
bytes32(0),
|
||||||
_delegationFactory.createDelegation(_parentDelegation),
|
_delegationFactory.createDelegation(_parentDelegation),
|
||||||
|
_proposalFactory,
|
||||||
|
_stakeValue,
|
||||||
_quorumType,
|
_quorumType,
|
||||||
startBlockDelay,
|
startBlockDelay,
|
||||||
votingBlockDelay,
|
votingBlockDelay,
|
||||||
|
@ -75,6 +82,9 @@ contract Democracy {
|
||||||
require(address(delegation) != address(0), "Invalid topic");
|
require(address(delegation) != address(0), "Invalid topic");
|
||||||
require(isTopicAllowed(_topicId, _destination, _data)); //require call allowance
|
require(isTopicAllowed(_topicId, _destination, _data)); //require call allowance
|
||||||
require(blockStart >= block.number + topic.startBlockDelay, "Bad blockStart");
|
require(blockStart >= block.number + topic.startBlockDelay, "Bad blockStart");
|
||||||
|
if(topic.stakeValue > 0) {
|
||||||
|
require(token.transferFrom(msg.sender, address(this), topic.stakeValue), "Stake payment failed");
|
||||||
|
}
|
||||||
uint256 blockEnd = blockStart + topic.votingBlockDelay;
|
uint256 blockEnd = blockStart + topic.votingBlockDelay;
|
||||||
bytes32 dataHash = keccak256(
|
bytes32 dataHash = keccak256(
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
|
@ -83,8 +93,9 @@ contract Democracy {
|
||||||
_data
|
_data
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
Proposal proposal = proposalFactory.createProposal(token, delegation, dataHash, topic.tabulationBlockDelay, blockStart, blockEnd, topic.quorum);
|
Proposal proposal = topic.proposalFactory.createProposal(token, delegation, dataHash, topic.tabulationBlockDelay, blockStart, blockEnd, topic.quorum);
|
||||||
proposals[address(proposal)] = ProposalData(_topicId, _destination, _data);
|
|
||||||
|
proposals[address(proposal)] = ProposalData(msg.sender, topic.stakeValue, _topicId, _destination, _data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeProposal(
|
function executeProposal(
|
||||||
|
@ -98,11 +109,11 @@ contract Democracy {
|
||||||
delete proposals[address(proposal)];
|
delete proposals[address(proposal)];
|
||||||
bool approved = proposal.isApproved();
|
bool approved = proposal.isApproved();
|
||||||
proposal.clear();
|
proposal.clear();
|
||||||
|
if(pdata.lockedStake > 0) {
|
||||||
if(approved){
|
token.transfer(pdata.proponent, pdata.lockedStake);
|
||||||
require(isTopicAllowed(pdata.topic, pdata.destination, pdata.data)); //require call allowance
|
}
|
||||||
//execute the call
|
if(approved && isTopicAllowed(pdata.topic, pdata.destination, pdata.data)){
|
||||||
(success, r) = pdata.destination.call(pdata.data);
|
(success, r) = pdata.destination.call(pdata.data); //execute the call
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -119,7 +130,9 @@ contract Democracy {
|
||||||
|
|
||||||
function addTopic(
|
function addTopic(
|
||||||
bytes32 topicId,
|
bytes32 topicId,
|
||||||
|
ProposalFactory _proposalFactory,
|
||||||
bytes32 parentTopic,
|
bytes32 parentTopic,
|
||||||
|
uint256 stakeValue,
|
||||||
Proposal.QuorumType quorum,
|
Proposal.QuorumType quorum,
|
||||||
uint256 startBlockDelay,
|
uint256 startBlockDelay,
|
||||||
uint256 votingBlockDelay,
|
uint256 votingBlockDelay,
|
||||||
|
@ -142,6 +155,8 @@ contract Democracy {
|
||||||
topics[topicId] = Topic(
|
topics[topicId] = Topic(
|
||||||
parentTopic,
|
parentTopic,
|
||||||
delegationFactory.createDelegation(parentDelegation),
|
delegationFactory.createDelegation(parentDelegation),
|
||||||
|
_proposalFactory,
|
||||||
|
_stakeValue,
|
||||||
quorum,
|
quorum,
|
||||||
startBlockDelay,
|
startBlockDelay,
|
||||||
votingBlockDelay,
|
votingBlockDelay,
|
||||||
|
|
Loading…
Reference in New Issue