From 19518435fa21c314babb7446ca0cfd339f5fd100 Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 8 Apr 2018 12:55:39 +0200 Subject: [PATCH] Allow Contributors management by core contirbutors So far we only allowed calls to the Contributors contract from the Operator. With the new registry concept we can call functions again directly on the Contributors contract (without the need to call it through the operator). This changes the authentication for the contributor management functions to allow either core contributors or the operator to call them. In the future I envision a bit more flexible and configurable authentication concept that can more easily evolve over time. --- config/seeds.js | 6 ++++-- contracts/Contributors.sol | 36 ++++++++++++++++++++---------------- scripts/add-contributor.js | 4 ++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/config/seeds.js b/config/seeds.js index 47ce148..90badf1 100644 --- a/config/seeds.js +++ b/config/seeds.js @@ -1,10 +1,12 @@ let contractCalls = { - Operator: { + Contributors: { addContributor: [ // make sure to use an IPFS hash of one of the objects in ipfsContent ['0x24dd2aedd8a9fe52ac071b3a23b2fc8f225c185e', '0x272bbfc66166f26cae9c9b96b7f9590e095f02edf342ac2dd71e1667a12116ca', 18, 32, true], // QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj ['0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827', '0x9569ed44826286597982e40bbdff919c6b7752e29d13250efca452644e6b4b25', 18, 32, true] // QmYPu8zvtfDy18ZqHCviVxnKtxycw5UTJLJyk9oAEjWfnL - ], + ] + }, + Operator: { addProposal: [ [1, 23, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" [2, 42, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" diff --git a/contracts/Contributors.sol b/contracts/Contributors.sol index b595c60..eeec329 100644 --- a/contracts/Contributors.sol +++ b/contracts/Contributors.sol @@ -23,6 +23,11 @@ contract Contributors is Upgradeable { event ContributorAddressUpdated(uint id, address oldAddress, address newAddress); event ContributorAdded(uint id, address _address); + modifier onlyCoreOrOperator() { + require(msg.sender == registry.getProxyFor('Operator') || addressIsCore(msg.sender)); + _; + } + function initialize(address sender) public payable { require(msg.sender == address(registry)); uint _id = 1; @@ -44,14 +49,14 @@ contract Contributors is Upgradeable { return count; } - function updateContributorAddress(uint _id, address _oldAddress, address _newAddress) public onlyRegistryContractFor('Operator') { + function updateContributorAddress(uint _id, address _oldAddress, address _newAddress) public onlyCoreOrOperator { contributorIds[_oldAddress] = 0; contributorIds[_newAddress] = _id; contributors[_id].account = _newAddress; ContributorAddressUpdated(_id, _oldAddress, _newAddress); } - function updateContributorIpfsHash(uint _id, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public onlyRegistryContractFor('Operator') { + function updateContributorIpfsHash(uint _id, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public onlyCoreOrOperator { Contributor storage c = contributors[_id]; bytes32 _oldIpfsHash = c.ipfsHash; c.ipfsHash = _ipfsHash; @@ -61,22 +66,21 @@ contract Contributors is Upgradeable { ContributorProfileUpdated(_id, _oldIpfsHash, c.ipfsHash); } - function addContributor(address _address, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize, bool isCore) public onlyRegistryContractFor('Operator') { + function addContributor(address _address, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize, bool _isCore) public onlyCoreOrOperator { + require(!addressExists(_address)); uint _id = contributorsCount + 1; - if (contributors[_id].exists != true) { - Contributor storage c = contributors[_id]; - c.exists = true; - c.isCore = isCore; - c.hashFunction = _hashFunction; - c.hashSize = _hashSize; - c.ipfsHash = _ipfsHash; - c.account = _address; - contributorIds[_address] = _id; + assert(!contributors[_id].exists); // this can not be acually + Contributor storage c = contributors[_id]; + c.exists = true; + c.isCore = _isCore; + c.hashFunction = _hashFunction; + c.hashSize = _hashSize; + c.ipfsHash = _ipfsHash; + c.account = _address; + contributorIds[_address] = _id; - contributorsCount += 1; - - ContributorAdded(_id, _address); - } + contributorsCount += 1; + ContributorAdded(_id, _address); } function isCore(uint _id) view public returns (bool) { diff --git a/scripts/add-contributor.js b/scripts/add-contributor.js index 1ea00ee..e003bd9 100644 --- a/scripts/add-contributor.js +++ b/scripts/add-contributor.js @@ -30,7 +30,7 @@ module.exports = function(callback) { let ipfsHash = process.argv[5] || 'QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj'; let contributorMultihash = getBytes32FromMultiash(ipfsHash); let isCore = true; - let contributorResult = await operator.addContributor(contributorToAddAddress, contributorMultihash.digest, contributorMultihash.hashFunction, contributorMultihash.size, isCore); + let contributorResult = await contributors.addContributor(contributorToAddAddress, contributorMultihash.digest, contributorMultihash.hashFunction, contributorMultihash.size, isCore); console.log('Contributor added, tx: ', contributorResult.tx); let contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress); @@ -39,7 +39,7 @@ module.exports = function(callback) { console.log('Proposal added, tx: ', proposalResult.tx); let proposalId = await operator.proposalsCount(); - let votingResult = operator.vote(proposalId.toNumber()-1); + let votingResult = await operator.vote(proposalId.toNumber()-1); console.log('Voted for proposal', proposalId.toString(), votingResult.tx); callback();