Merge pull request #17 from 67P/refactor/authentication
Allow Contributors management by core contirbutors
This commit is contained in:
commit
ef3b3dd6bb
@ -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"
|
||||
|
@ -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,12 +66,13 @@ 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) {
|
||||
assert(!contributors[_id].exists); // this can not be acually
|
||||
Contributor storage c = contributors[_id];
|
||||
c.exists = true;
|
||||
c.isCore = isCore;
|
||||
c.isCore = _isCore;
|
||||
c.hashFunction = _hashFunction;
|
||||
c.hashSize = _hashSize;
|
||||
c.ipfsHash = _ipfsHash;
|
||||
@ -74,10 +80,8 @@ contract Contributors is Upgradeable {
|
||||
contributorIds[_address] = _id;
|
||||
|
||||
contributorsCount += 1;
|
||||
|
||||
ContributorAdded(_id, _address);
|
||||
}
|
||||
}
|
||||
|
||||
function isCore(uint _id) view public returns (bool) {
|
||||
return contributors[_id].isCore;
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user