More consistent contract parameter naming

This commit is contained in:
bumi 2018-04-10 16:25:17 +02:00
parent e9c6f1e4a7
commit 7f30006703
2 changed files with 25 additions and 46 deletions

View File

@ -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 creator, uint recipientId, uint256 amount);
event ProposalVoted(uint256 id, address voter, uint256 totalVotes); event ProposalVoted(uint256 id, address voter, uint256 totalVotes);
event ProposalExecuted(uint256 id, uint recipient, uint256 amount); event ProposalExecuted(uint256 id, uint recipientId, uint256 amount);
modifier coreOnly() { modifier coreOnly() {
require(contributorsContract().addressIsCore(msg.sender)); require(contributorsContract().addressIsCore(msg.sender));
@ -55,45 +55,29 @@ 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 recipientId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public returns {
contributorsContract().addContributor(_address, _ipfsHash, _hashFunction, _hashSize, _isCore); require(contributorsContract().exists(recipientId));
}
function updateContributorIpfsHash(uint _id, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public coreOnly {
contributorsContract().updateContributorIpfsHash(_id, _ipfsHash, _hashFunction, _hashSize);
}
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; proposalId = proposalsCount + 1;
uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75;
var p = proposals[proposalId]; var p = proposals[proposalId];
p.creator = msg.sender; p.creator = msg.sender;
p.recipientId = _recipient; p.recipientId = recipientId;
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.recipientId, 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 id) 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) {
Proposal storage p = proposals[_proposalId]; Proposal storage p = proposals[id];
return ( return (
p.creator, p.creator,
p.recipientId, p.recipientId,
@ -109,25 +93,22 @@ 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, msg.sender, 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);
@ -135,7 +116,6 @@ contract Operator is Upgradeable {
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.recipientId, p.amount);
return true;
} }
} }

View File

@ -17,12 +17,11 @@ contract Token is Upgradeable, BasicToken {
decimals = 18; decimals = 18;
} }
function mintFor(address _recipient, uint256 _amount, uint _proposalId) onlyRegistryContractFor('Operator') public returns (bool success) { function mintFor(address recipientAddress, uint256 amount, uint proposalId) onlyRegistryContractFor('Operator') public {
totalSupply_ = totalSupply_.add(_amount); totalSupply_ = totalSupply_.add(amount);
balances[_recipient] = balances[_recipient].add(_amount); balances[recipientAddress] = balances[recipientAddress].add(amount);
LogMint(_recipient, _amount, _proposalId); LogMint(recipientAddress, amount, proposalId);
return true;
} }
} }