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.
This commit is contained in:
bumi 2018-04-08 12:55:39 +02:00
parent 170532a128
commit 19518435fa
3 changed files with 26 additions and 20 deletions

View File

@ -1,10 +1,12 @@
let contractCalls = { let contractCalls = {
Operator: { Contributors: {
addContributor: [ addContributor: [
// make sure to use an IPFS hash of one of the objects in ipfsContent // make sure to use an IPFS hash of one of the objects in ipfsContent
['0x24dd2aedd8a9fe52ac071b3a23b2fc8f225c185e', '0x272bbfc66166f26cae9c9b96b7f9590e095f02edf342ac2dd71e1667a12116ca', 18, 32, true], // QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj ['0x24dd2aedd8a9fe52ac071b3a23b2fc8f225c185e', '0x272bbfc66166f26cae9c9b96b7f9590e095f02edf342ac2dd71e1667a12116ca', 18, 32, true], // QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj
['0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827', '0x9569ed44826286597982e40bbdff919c6b7752e29d13250efca452644e6b4b25', 18, 32, true] // QmYPu8zvtfDy18ZqHCviVxnKtxycw5UTJLJyk9oAEjWfnL ['0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827', '0x9569ed44826286597982e40bbdff919c6b7752e29d13250efca452644e6b4b25', 18, 32, true] // QmYPu8zvtfDy18ZqHCviVxnKtxycw5UTJLJyk9oAEjWfnL
], ]
},
Operator: {
addProposal: [ addProposal: [
[1, 23, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" [1, 23, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs"
[2, 42, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" [2, 42, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs"

View File

@ -23,6 +23,11 @@ contract Contributors is Upgradeable {
event ContributorAddressUpdated(uint id, address oldAddress, address newAddress); event ContributorAddressUpdated(uint id, address oldAddress, address newAddress);
event ContributorAdded(uint id, address _address); event ContributorAdded(uint id, address _address);
modifier onlyCoreOrOperator() {
require(msg.sender == registry.getProxyFor('Operator') || addressIsCore(msg.sender));
_;
}
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;
@ -44,14 +49,14 @@ contract Contributors is Upgradeable {
return count; 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[_oldAddress] = 0;
contributorIds[_newAddress] = _id; contributorIds[_newAddress] = _id;
contributors[_id].account = _newAddress; contributors[_id].account = _newAddress;
ContributorAddressUpdated(_id, _oldAddress, _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]; Contributor storage c = contributors[_id];
bytes32 _oldIpfsHash = c.ipfsHash; bytes32 _oldIpfsHash = c.ipfsHash;
c.ipfsHash = _ipfsHash; c.ipfsHash = _ipfsHash;
@ -61,12 +66,13 @@ contract Contributors is Upgradeable {
ContributorProfileUpdated(_id, _oldIpfsHash, c.ipfsHash); 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; uint _id = contributorsCount + 1;
if (contributors[_id].exists != true) { assert(!contributors[_id].exists); // this can not be acually
Contributor storage 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;
c.hashSize = _hashSize; c.hashSize = _hashSize;
c.ipfsHash = _ipfsHash; c.ipfsHash = _ipfsHash;
@ -74,10 +80,8 @@ contract Contributors is Upgradeable {
contributorIds[_address] = _id; contributorIds[_address] = _id;
contributorsCount += 1; contributorsCount += 1;
ContributorAdded(_id, _address); ContributorAdded(_id, _address);
} }
}
function isCore(uint _id) view public returns (bool) { function isCore(uint _id) view public returns (bool) {
return contributors[_id].isCore; return contributors[_id].isCore;

View File

@ -30,7 +30,7 @@ module.exports = function(callback) {
let ipfsHash = process.argv[5] || 'QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj'; let ipfsHash = process.argv[5] || 'QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj';
let contributorMultihash = getBytes32FromMultiash(ipfsHash); let contributorMultihash = getBytes32FromMultiash(ipfsHash);
let isCore = true; 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); console.log('Contributor added, tx: ', contributorResult.tx);
let contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress); let contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress);
@ -39,7 +39,7 @@ module.exports = function(callback) {
console.log('Proposal added, tx: ', proposalResult.tx); console.log('Proposal added, tx: ', proposalResult.tx);
let proposalId = await operator.proposalsCount(); 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); console.log('Voted for proposal', proposalId.toString(), votingResult.tx);
callback(); callback();