|
|
|
@@ -7,8 +7,8 @@ import './Contributors.sol';
|
|
|
|
contract Operator is Upgradeable {
|
|
|
|
contract Operator is Upgradeable {
|
|
|
|
|
|
|
|
|
|
|
|
struct Proposal {
|
|
|
|
struct Proposal {
|
|
|
|
address creator;
|
|
|
|
address creatorAccount;
|
|
|
|
uint recipientId;
|
|
|
|
uint contributorId;
|
|
|
|
uint votesCount;
|
|
|
|
uint votesCount;
|
|
|
|
uint votesNeeded;
|
|
|
|
uint votesNeeded;
|
|
|
|
uint256 amount;
|
|
|
|
uint256 amount;
|
|
|
|
@@ -24,9 +24,9 @@ contract Operator is Upgradeable {
|
|
|
|
mapping(uint256 => Proposal) public proposals;
|
|
|
|
mapping(uint256 => Proposal) public proposals;
|
|
|
|
uint256 public proposalsCount;
|
|
|
|
uint256 public proposalsCount;
|
|
|
|
|
|
|
|
|
|
|
|
event ProposalCreated(uint256 id, address creator, uint recipient, uint256 amount);
|
|
|
|
event ProposalCreated(uint256 id, address creatorAccount, uint256 contributorId, uint256 amount);
|
|
|
|
event ProposalVoted(uint256 id, address voter, uint256 totalVotes);
|
|
|
|
event ProposalVoted(uint256 id, uint256 voterId, uint256 totalVotes);
|
|
|
|
event ProposalExecuted(uint256 id, uint recipient, uint256 amount);
|
|
|
|
event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount);
|
|
|
|
|
|
|
|
|
|
|
|
modifier coreOnly() {
|
|
|
|
modifier coreOnly() {
|
|
|
|
require(contributorsContract().addressIsCore(msg.sender));
|
|
|
|
require(contributorsContract().addressIsCore(msg.sender));
|
|
|
|
@@ -55,48 +55,34 @@ contract Operator is Upgradeable {
|
|
|
|
return contributorsContract().coreContributorsCount();
|
|
|
|
return contributorsContract().coreContributorsCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addContributor(address _address, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize, bool _isCore) public coreOnly {
|
|
|
|
function addProposal(uint contributorId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public {
|
|
|
|
contributorsContract().addContributor(_address, _ipfsHash, _hashFunction, _hashSize, _isCore);
|
|
|
|
require(contributorsContract().exists(contributorId));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateContributorIpfsHash(uint _id, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public coreOnly {
|
|
|
|
uint256 proposalId = proposalsCount + 1;
|
|
|
|
contributorsContract().updateContributorIpfsHash(_id, _ipfsHash, _hashFunction, _hashSize);
|
|
|
|
uint256 _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getContributor(uint _id) view public returns (address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore) {
|
|
|
|
|
|
|
|
bool exists;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(account, ipfsHash, hashFunction, hashSize, isCore, exists) = contributorsContract().contributors(_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require(exists);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addProposal(uint _recipient, uint256 _amount, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public returns (uint256 proposalId) {
|
|
|
|
|
|
|
|
require(contributorsContract().exists(_recipient));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proposalId = proposalsCount + 1;
|
|
|
|
|
|
|
|
uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var p = proposals[proposalId];
|
|
|
|
var p = proposals[proposalId];
|
|
|
|
p.creator = msg.sender;
|
|
|
|
p.creatorAccount = msg.sender;
|
|
|
|
p.recipientId = _recipient;
|
|
|
|
p.contributorId = contributorId;
|
|
|
|
p.amount = _amount;
|
|
|
|
p.amount = amount;
|
|
|
|
p.ipfsHash = _ipfsHash;
|
|
|
|
p.ipfsHash = ipfsHash;
|
|
|
|
p.hashFunction = _hashFunction;
|
|
|
|
p.hashFunction = hashFunction;
|
|
|
|
p.hashSize = _hashSize;
|
|
|
|
p.hashSize = hashSize;
|
|
|
|
p.votesCount = 0;
|
|
|
|
p.votesCount = 0;
|
|
|
|
p.votesNeeded = _votesNeeded;
|
|
|
|
p.votesNeeded = _votesNeeded;
|
|
|
|
p.exists = true;
|
|
|
|
p.exists = true;
|
|
|
|
|
|
|
|
|
|
|
|
proposalsCount++;
|
|
|
|
proposalsCount++;
|
|
|
|
ProposalCreated(proposalId, msg.sender, p.recipientId, p.amount);
|
|
|
|
ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getProposal(uint _proposalId) public view returns (address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) {
|
|
|
|
function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 contributorId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) {
|
|
|
|
Proposal storage p = proposals[_proposalId];
|
|
|
|
id = proposalId;
|
|
|
|
|
|
|
|
Proposal storage p = proposals[id];
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
p.creator,
|
|
|
|
id,
|
|
|
|
p.recipientId,
|
|
|
|
p.creatorAccount,
|
|
|
|
|
|
|
|
p.contributorId,
|
|
|
|
p.votesCount,
|
|
|
|
p.votesCount,
|
|
|
|
p.votesNeeded,
|
|
|
|
p.votesNeeded,
|
|
|
|
p.amount,
|
|
|
|
p.amount,
|
|
|
|
@@ -109,33 +95,29 @@ contract Operator is Upgradeable {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function vote(uint256 _proposalId) public coreOnly returns (uint _pId, bool _executed) {
|
|
|
|
function vote(uint256 proposalId) public coreOnly {
|
|
|
|
var p = proposals[_proposalId];
|
|
|
|
var p = proposals[proposalId];
|
|
|
|
require(!p.executed);
|
|
|
|
require(!p.executed);
|
|
|
|
uint256 contributorId = contributorsContract().getContributorIdByAddress(msg.sender);
|
|
|
|
uint256 voterId = contributorsContract().getContributorIdByAddress(msg.sender);
|
|
|
|
require(p.votes[contributorId] != true);
|
|
|
|
require(p.votes[voterId] != true);
|
|
|
|
p.voterIds.push(contributorId);
|
|
|
|
p.voterIds.push(voterId);
|
|
|
|
p.votes[contributorId] = true;
|
|
|
|
p.votes[voterId] = true;
|
|
|
|
|
|
|
|
|
|
|
|
p.votesCount++;
|
|
|
|
p.votesCount++;
|
|
|
|
_executed = false;
|
|
|
|
|
|
|
|
_pId = _proposalId;
|
|
|
|
|
|
|
|
if (p.votesCount >= p.votesNeeded) {
|
|
|
|
if (p.votesCount >= p.votesNeeded) {
|
|
|
|
executeProposal(_proposalId);
|
|
|
|
executeProposal(proposalId);
|
|
|
|
_executed = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProposalVoted(_pId, msg.sender, p.votesCount);
|
|
|
|
ProposalVoted(proposalId, voterId, p.votesCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function executeProposal(uint proposalId) private returns (bool) {
|
|
|
|
function executeProposal(uint proposalId) private {
|
|
|
|
var p = proposals[proposalId];
|
|
|
|
var p = proposals[proposalId];
|
|
|
|
require(!p.executed);
|
|
|
|
require(!p.executed);
|
|
|
|
require(p.votesCount >= p.votesNeeded);
|
|
|
|
require(p.votesCount >= p.votesNeeded);
|
|
|
|
address recipientAddress = contributorsContract().getContributorAddressById(p.recipientId);
|
|
|
|
address recipientAddress = contributorsContract().getContributorAddressById(p.contributorId);
|
|
|
|
tokenContract().mintFor(recipientAddress, p.amount, proposalId);
|
|
|
|
tokenContract().mintFor(recipientAddress, p.amount, proposalId);
|
|
|
|
p.executed = true;
|
|
|
|
p.executed = true;
|
|
|
|
ProposalExecuted(proposalId, p.recipientId, p.amount);
|
|
|
|
ProposalExecuted(proposalId, p.contributorId, p.amount);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|