Newer solidity style #16

Merged
bumi merged 1 commits from refactor/new-solidity-style into master 2018-04-07 20:24:31 +00:00
2 changed files with 21 additions and 21 deletions

View File

@ -24,7 +24,7 @@ contract Contributors is Upgradeable {
function initialize(address sender) public payable { function initialize(address sender) public payable {
require(msg.sender == address(registry)); require(msg.sender == address(registry));
uint _id = 1; uint _id = 1;
Contributor c = contributors[_id]; Contributor storage c = contributors[_id];
c.exists = true; c.exists = true;
c.isCore = true; c.isCore = true;
c.account = sender; c.account = sender;
@ -32,7 +32,7 @@ contract Contributors is Upgradeable {
contributorsCount += 1; contributorsCount += 1;
} }
function coreContributorsCount() constant public returns (uint) { function coreContributorsCount() view public returns (uint) {
uint count = 0; uint count = 0;
for (uint256 i = 1; i <= contributorsCount; i++) { for (uint256 i = 1; i <= contributorsCount; i++) {
if (contributors[i].isCore) { if (contributors[i].isCore) {
@ -50,7 +50,7 @@ contract Contributors is Upgradeable {
} }
function updateContributorProfileHash(uint _id, uint8 _hashFunction, uint8 _hashSize, bytes32 _profileHash) public onlyRegistryContractFor('Operator') { function updateContributorProfileHash(uint _id, uint8 _hashFunction, uint8 _hashSize, bytes32 _profileHash) public onlyRegistryContractFor('Operator') {
Contributor c = contributors[_id]; Contributor storage c = contributors[_id];
bytes32 _oldProfileHash = c.profileHash; bytes32 _oldProfileHash = c.profileHash;
c.profileHash = _profileHash; c.profileHash = _profileHash;
c.hashFunction = _hashFunction; c.hashFunction = _hashFunction;
@ -62,7 +62,7 @@ contract Contributors is Upgradeable {
function addContributor(address _address, uint8 _hashFunction, uint8 _hashSize, bytes32 _profileHash, bool isCore) public onlyRegistryContractFor('Operator') { function addContributor(address _address, uint8 _hashFunction, uint8 _hashSize, bytes32 _profileHash, bool isCore) public onlyRegistryContractFor('Operator') {
uint _id = contributorsCount + 1; uint _id = contributorsCount + 1;
if (contributors[_id].exists != true) { if (contributors[_id].exists != true) {
Contributor c = contributors[_id]; Contributor storage c = contributors[_id];
c.exists = true; c.exists = true;
c.isCore = isCore; c.isCore = isCore;
c.hashFunction = _hashFunction; c.hashFunction = _hashFunction;
@ -77,27 +77,27 @@ contract Contributors is Upgradeable {
} }
} }
function isCore(uint _id) constant public returns (bool) { function isCore(uint _id) view public returns (bool) {
return contributors[_id].isCore; return contributors[_id].isCore;
} }
function exists(uint _id) constant public returns (bool) { function exists(uint _id) view public returns (bool) {
return contributors[_id].exists; return contributors[_id].exists;
} }
function addressIsCore(address _address) constant public returns (bool) { function addressIsCore(address _address) view public returns (bool) {
return getContributorByAddress(_address).isCore; return getContributorByAddress(_address).isCore;
} }
function addressExists(address _address) constant public returns (bool) { function addressExists(address _address) view public returns (bool) {
return getContributorByAddress(_address).exists; return getContributorByAddress(_address).exists;
} }
function getContributorIdByAddress(address _address) constant public returns (uint) { function getContributorIdByAddress(address _address) view public returns (uint) {
return contributorIds[_address]; return contributorIds[_address];
} }
function getContributorAddressById(uint _id) constant public returns (address) { function getContributorAddressById(uint _id) view public returns (address) {
return contributors[_id].account; return contributors[_id].account;
} }

View File

@ -46,10 +46,10 @@ contract Operator is Upgradeable {
return Token(registry.getProxyFor('Token')); return Token(registry.getProxyFor('Token'));
} }
function contributorsCount() constant public returns (uint) { function contributorsCount() view public returns (uint) {
return contributorsContract().contributorsCount(); return contributorsContract().contributorsCount();
} }
function coreContributorsCount() constant public returns (uint) { function coreContributorsCount() view public returns (uint) {
return contributorsContract().coreContributorsCount(); return contributorsContract().coreContributorsCount();
} }
@ -61,15 +61,15 @@ contract Operator is Upgradeable {
contributorsContract().updateContributorProfileHash(_id, _hashFunction, _hashSize, _profileHash); contributorsContract().updateContributorProfileHash(_id, _hashFunction, _hashSize, _profileHash);
} }
function getContributor(uint _id) constant public returns (address account, uint8 hashFunction, uint8 hashSize, bytes32 profileHash, bool isCore) { function getContributor(uint _id) view public returns (address account, uint8 hashFunction, uint8 hashSize, bytes32 profileHash, bool isCore) {
bool exists; bool exists;
(account, profileHash, hashFunction, hashSize, isCore, exists) = contributorsContract().contributors(_id); (account, profileHash, hashFunction, hashSize, isCore, exists) = contributorsContract().contributors(_id);
if (!exists) { throw; } require(exists);
} }
function proposalsCount() constant public returns (uint) { function proposalsCount() view public returns (uint) {
return proposals.length; return proposals.length;
} }
@ -97,8 +97,8 @@ contract Operator is Upgradeable {
function vote(uint256 _proposalId) public coreOnly returns (uint _pId, bool _executed) { function vote(uint256 _proposalId) public coreOnly returns (uint _pId, bool _executed) {
var p = proposals[_proposalId]; var p = proposals[_proposalId];
if (p.executed) { throw; } require(!p.executed);
if (p.votes[msg.sender] == true) { throw; } require(p.votes[msg.sender] != true);
p.votes[msg.sender] = true; p.votes[msg.sender] = true;
p.votesCount++; p.votesCount++;
_executed = false; _executed = false;
@ -110,15 +110,15 @@ contract Operator is Upgradeable {
ProposalVoted(_pId, msg.sender, p.votesCount); ProposalVoted(_pId, msg.sender, p.votesCount);
} }
function hasVotedFor(address _sender, uint256 _proposalId) public constant returns (bool) { function hasVotedFor(address _sender, uint256 _proposalId) public view returns (bool) {
Proposal p = proposals[_proposalId]; Proposal storage p = proposals[_proposalId];
return p.exists && p.votes[_sender]; return p.exists && p.votes[_sender];
} }
function executeProposal(uint proposalId) private returns (bool) { function executeProposal(uint proposalId) private returns (bool) {
var p = proposals[proposalId]; var p = proposals[proposalId];
if (p.executed) { throw; } require(!p.executed);
if (p.votesCount < p.votesNeeded) { throw; } require(p.votesCount >= p.votesNeeded);
address recipientAddress = contributorsContract().getContributorAddressById(p.recipientId); address recipientAddress = contributorsContract().getContributorAddressById(p.recipientId);
tokenContract().mintFor(recipientAddress, p.amount, proposalId); tokenContract().mintFor(recipientAddress, p.amount, proposalId);
p.executed = true; p.executed = true;