Dynamic function to test for core contributor flag #76

Merged
bumi merged 1 commits from features/dynamic-core-flag into master 2019-04-06 13:19:02 +00:00
4 changed files with 11 additions and 20 deletions

View File

@ -16,7 +16,6 @@ contract Contributor is AragonApp {
bytes32 ipfsHash; bytes32 ipfsHash;
uint8 hashFunction; uint8 hashFunction;
uint8 hashSize; uint8 hashSize;
bool isCore;
bool exists; bool exists;
} }
@ -33,14 +32,6 @@ contract Contributor is AragonApp {
event ContributorAdded(uint32 id, address account); event ContributorAdded(uint32 id, address account);
function initialize(address root,bytes32[4] _appIds) public onlyInit { function initialize(address root,bytes32[4] _appIds) public onlyInit {
uint32 _id = contributorsCount + 1;
Contributor storage c = contributors[_id];
c.exists = true;
c.isCore = true;
c.account = root;
contributorIds[root] = _id;
contributorsCount += 1;
appIds = _appIds; appIds = _appIds;
initialized(); initialized();
@ -55,7 +46,7 @@ contract Contributor is AragonApp {
function coreContributorsCount() view public returns (uint32) { function coreContributorsCount() view public returns (uint32) {
uint32 count = 0; uint32 count = 0;
for (uint32 i = 1; i <= contributorsCount; i++) { for (uint32 i = 1; i <= contributorsCount; i++) {
if (contributors[i].isCore) { if (isCoreTeam(i)) {
count += 1; count += 1;
} }
} }
@ -79,13 +70,12 @@ contract Contributor is AragonApp {
ContributorProfileUpdated(id, oldIpfsHash, c.ipfsHash); ContributorProfileUpdated(id, oldIpfsHash, c.ipfsHash);
} }
function addContributor(address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) { function addContributor(address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) {
require(!addressExists(account)); require(!addressExists(account));
uint32 _id = contributorsCount + 1; uint32 _id = contributorsCount + 1;
assert(!contributors[_id].exists); // this can not be acually 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.ipfsHash = ipfsHash; c.ipfsHash = ipfsHash;
c.hashFunction = hashFunction; c.hashFunction = hashFunction;
c.hashSize = hashSize; c.hashSize = hashSize;
@ -96,8 +86,10 @@ contract Contributor is AragonApp {
emit ContributorAdded(_id, account); emit ContributorAdded(_id, account);
} }
function isCore(uint32 id) view public returns (bool) { function isCoreTeam(uint32 id) view public returns (bool) {
return contributors[id].isCore; // TODO: for simplicity we simply define the first contributors as core
// later this needs to be changed to something more dynamic
return id < 7;
} }
function exists(uint32 id) view public returns (bool) { function exists(uint32 id) view public returns (bool) {
@ -105,7 +97,8 @@ contract Contributor is AragonApp {
} }
function addressIsCore(address account) view public returns (bool) { function addressIsCore(address account) view public returns (bool) {
return getContributorByAddress(account).isCore; uint32 id = getContributorIdByAddress(account);
return isCoreTeam(id);
} }
function addressExists(address account) view public returns (bool) { function addressExists(address account) view public returns (bool) {
@ -132,7 +125,7 @@ contract Contributor is AragonApp {
ipfsHash = c.ipfsHash; ipfsHash = c.ipfsHash;
hashFunction = c.hashFunction; hashFunction = c.hashFunction;
hashSize = c.hashSize; hashSize = c.hashSize;
isCore = c.isCore; isCore = isCoreTeam(id);
address token = getTokenContract(); address token = getTokenContract();
balance = ITokenBalance(token).balanceOf(c.account); balance = ITokenBalance(token).balanceOf(c.account);
exists = c.exists; exists = c.exists;

File diff suppressed because one or more lines are too long

View File

@ -67,7 +67,6 @@ class Contributor extends Base {
ipfsHashAttr.hashDigest, ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction, ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize, ipfsHashAttr.hashSize,
contributorAttr.isCore,
]; ];
return this.functions.addContributor(...contributor, callOptions); return this.functions.addContributor(...contributor, callOptions);

View File

@ -23,7 +23,6 @@ module.exports = async function(callback) {
let contributorAttributes = { let contributorAttributes = {
account: await prompt('Contributor address: ', {}), account: await prompt('Contributor address: ', {}),
name: await prompt('Name: '), name: await prompt('Name: '),
isCore: await prompt('core? y/n') === 'y',
kind: await prompt('Kind (default person): ', {default: 'person'}), kind: await prompt('Kind (default person): ', {default: 'person'}),
url: await prompt('URL: '), url: await prompt('URL: '),
github_username: await prompt('GitHub username: '), github_username: await prompt('GitHub username: '),
@ -34,7 +33,7 @@ module.exports = async function(callback) {
console.log("\nAdding contributor:"); console.log("\nAdding contributor:");
console.log(contributorAttributes); console.log(contributorAttributes);
kredits.Contributor.add(contributorAttributes, { gasLimit: 250000 }).then((result) => { kredits.Contributor.add(contributorAttributes, { gasLimit: 350000 }).then((result) => {
console.log("\n\nResult:"); console.log("\n\nResult:");
console.log(result); console.log(result);
callback(); callback();