From 20acfc70e352622a210a8955d33d0424ae597322 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 14:43:38 +0200 Subject: [PATCH 01/13] Use ID instead of address for contribution owner --- apps/contribution/contracts/Contribution.sol | 76 +++++++++++++++----- config/seeds.js | 12 ++-- lib/abis/Contribution.json | 2 +- lib/contracts/contribution.js | 26 +++++-- 4 files changed, 86 insertions(+), 30 deletions(-) diff --git a/apps/contribution/contracts/Contribution.sol b/apps/contribution/contracts/Contribution.sol index 4dcb62f..1717717 100644 --- a/apps/contribution/contracts/Contribution.sol +++ b/apps/contribution/contracts/Contribution.sol @@ -7,17 +7,25 @@ interface IToken { function mintFor(address contributorAccount, uint256 amount, uint256 contributionId) public; } +interface ContributorInterface { + function getContributorAddressById(uint256 contributorId) public view returns (address); + function getContributorIdByAddress(address contributorAccount) public view returns (uint256); + // TODO Maybe use for validation + // function exists(uint256 contributorId) public view returns (bool); +} + contract Contribution is AragonApp { bytes32 public constant ADD_CONTRIBUTION_ROLE = keccak256("ADD_CONTRIBUTION_ROLE"); bytes32 public constant VETO_CONTRIBUTION_ROLE = keccak256("VETO_CONTRIBUTION_ROLE"); bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb; + // ensure alphabetic order enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; struct ContributionData { - address contributor; + uint256 contributorId; uint256 amount; bool claimed; bytes32 hashDigest; @@ -28,19 +36,22 @@ contract Contribution is AragonApp { bool vetoed; bool exists; } + string internal name_; string internal symbol_; - mapping(uint256 => address) contributionOwner; - mapping(address => uint256[]) ownedContributions; + // map contribution ID to contributor + mapping(uint256 => uint256) public contributionOwner; + // map contributor to contribution IDs + mapping(uint256 => uint256[]) public ownedContributions; mapping(uint256 => ContributionData) public contributions; uint256 public contributionsCount; uint256 public blocksToWait = 0; - event ContributionAdded(uint256 id, address indexed contributor, uint256 amount); - event ContributionClaimed(uint256 id, address indexed contributor, uint256 amount); + event ContributionAdded(uint256 id, uint256 indexed contributorId, uint256 amount); + event ContributionClaimed(uint256 id, uint256 indexed contributorId, uint256 amount); event ContributionVetoed(uint256 id, address vetoedByAccount); function initialize(bytes32[4] _appIds) public onlyInit { @@ -48,11 +59,29 @@ contract Contribution is AragonApp { initialized(); } + // TODO refactor into a single function function getTokenContract() public view returns (address) { IKernel k = IKernel(kernel()); - return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]); } + function getContributorContract() public view returns (address) { + IKernel k = IKernel(kernel()); + return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contributor)]); + } + + function getContributorIdByAddress(address contributorAccount) public view returns (uint256) { + address contributor = getContributorContract(); + return ContributorInterface(contributor).getContributorIdByAddress(contributorAccount); + } + + function getContributorAddressById(uint256 contributorId) public view returns (uint256) { + address contributor = getContributorContract(); + return ContributorInterface(contributor).getContributorAddressById(contributorId); + } + + // + // Token standard functions (ERC 721) + // function name() external view returns (string) { return name_; @@ -62,30 +91,38 @@ contract Contribution is AragonApp { return symbol_; } + // Balance is amount of ERC271 tokens, not amount of kredits function balanceOf(address owner) public view returns (uint256) { require(owner != address(0)); - return ownedContributions[owner].length; + uint256 contributorId = getContributorIdByAddress(owner); + return ownedContributions[contributorId].length; } function ownerOf(uint256 contributionId) public view returns (address) { require(exists(contributionId)); - return contributions[contributionId].contributor; + uint256 contributorId = contributions[contributionId].contributorId; + return getContributorAddressById(contributorId); } - function tokenOfOwnerByIndex(address contributor, uint256 index) public view returns (uint256) { - return ownedContributions[contributor][index]; + function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) { + uint256 contributorId = getContributorIdByAddress(owner); + return ownedContributions[contributorId][index]; } function tokenMetadata(uint256 contributionId) public view returns (string) { return contributions[contributionId].tokenMetadataURL; } - function getContribution(uint256 contributionId) public view returns (uint256 id, address contributor, uint256 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint claimAfterBlock, bool exists, bool vetoed) { + // + // Custom functions + // + + function getContribution(uint256 contributionId) public view returns (uint256 id, uint256 contributorId, uint256 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint claimAfterBlock, bool exists, bool vetoed) { id = contributionId; ContributionData storage c = contributions[id]; return ( id, - c.contributor, + c.contributorId, c.amount, c.claimed, c.hashDigest, @@ -97,14 +134,14 @@ contract Contribution is AragonApp { ); } - function add(uint256 amount, address contributorAccount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) { + function add(uint256 amount, uint256 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) { //require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint256[](0)), 'nope'); uint256 contributionId = contributionsCount + 1; ContributionData storage c = contributions[contributionId]; c.exists = true; c.amount = amount; c.claimed = false; - c.contributor = contributorAccount; + c.contributorId = contributorId; c.hashDigest = hashDigest; c.hashFunction = hashFunction; c.hashSize = hashSize; @@ -112,10 +149,10 @@ contract Contribution is AragonApp { contributionsCount++; - contributionOwner[contributionId] = contributorAccount; - ownedContributions[contributorAccount].push(contributionId); + contributionOwner[contributionId] = contributorId; + ownedContributions[contributorId].push(contributionId); - emit ContributionAdded(contributionId, contributorAccount, amount); + emit ContributionAdded(contributionId, contributorId, amount); } function veto(uint256 contributionId) public isInitialized auth(VETO_CONTRIBUTION_ROLE) { @@ -136,8 +173,9 @@ contract Contribution is AragonApp { c.claimed = true; address token = getTokenContract(); - IToken(token).mintFor(c.contributor, c.amount, contributionId); - emit ContributionClaimed(contributionId, c.contributor, c.amount); + address contributorAccount = getContributorAddressById(c.contributorId); + IToken(token).mintFor(contributorAccount, c.amount, contributionId); + emit ContributionClaimed(contributionId, c.contributorId, c.amount); } function exists(uint256 contributionId) view public returns (bool) { diff --git a/config/seeds.js b/config/seeds.js index 8dce01e..a6d0562 100644 --- a/config/seeds.js +++ b/config/seeds.js @@ -1,12 +1,12 @@ const contractCalls = [ ['Contributor', 'add', [{ account: '0x7e8f313c56f809188313aa274fa67ee58c31515d', name: 'bumi', isCore: true, kind: 'person', url: '', github_username: 'bumi', github_uid: 318, wiki_username: 'bumi' }, { gasLimit: 200000 }]], ['Contributor', 'add', [{ account: '0x49575f3DD9a0d60aE661BC992f72D837A77f05Bc', name: 'raucao', isCore: true, kind: 'person', url: '', github_username: 'skddc', github_uid: 842, wiki_username: 'raucau' }, { gasLimit: 200000 }]], - ['Proposal', 'addProposal', [{ contributorId: 2, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], - ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], - ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Hacked on kredits', url: '' }, { gasLimit: 350000 }]], - ['Proposal', 'vote', [1, { gasLimit: 550000 }]], - ['Contribution', 'addContribution', [{ contributorAccount: '0x49575f3DD9a0d60aE661BC992f72D837A77f05Bc', amount: 5000, kind: 'dev', description: '[67P/kredits-contracts] Introduce contribution token', url: '' }, { gasLimit: 350000 }]], - ['Contribution', 'addContribution', [{ contributorAccount: '0x7e8f313c56f809188313aa274fa67ee58c31515d', amount: 1500, kind: 'dev', description: '[67P/kredits-web] Reviewed stuff', url: '' }, { gasLimit: 350000 }]], + // ['Proposal', 'addProposal', [{ contributorId: 2, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], + // ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], + // ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Hacked on kredits', url: '' }, { gasLimit: 350000 }]], + // ['Proposal', 'vote', [1, { gasLimit: 550000 }]], + ['Contribution', 'addContribution', [{ contributorId: 2, amount: 5000, kind: 'dev', description: '[67P/kredits-contracts] Introduce contribution token', url: '' }, { gasLimit: 350000 }]], + ['Contribution', 'addContribution', [{ contributorId: 3, amount: 1500, kind: 'dev', description: '[67P/kredits-web] Reviewed stuff', url: '' }, { gasLimit: 350000 }]], ['Contribution', 'claim', [1, { gasLimit: 300000 }]] ]; const funds = [ diff --git a/lib/abis/Contribution.json b/lib/abis/Contribution.json index 0f2b683..d2ae07f 100644 --- a/lib/abis/Contribution.json +++ b/lib/abis/Contribution.json @@ -1 +1 @@ -[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributions","outputs":[{"name":"contributor","type":"address"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"tokenMetadataURL","type":"string"},{"name":"claimAfterBlock","type":"uint256"},{"name":"vetoed","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributionsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"blocksToWait","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VETO_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributor","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributor","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"vetoedByAccount","type":"address"}],"name":"ContributionVetoed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributor","type":"address"},{"name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"tokenMetadata","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"getContribution","outputs":[{"name":"id","type":"uint256"},{"name":"contributor","type":"address"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"claimAfterBlock","type":"uint256"},{"name":"exists","type":"bool"},{"name":"vetoed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"},{"name":"contributorAccount","type":"address"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"add","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"veto","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"claim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributions","outputs":[{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"tokenMetadataURL","type":"string"},{"name":"claimAfterBlock","type":"uint256"},{"name":"vetoed","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributionsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"ownedContributions","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"blocksToWait","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VETO_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributionOwner","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"vetoedByAccount","type":"address"}],"name":"ContributionVetoed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getContributorContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorAccount","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorId","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"tokenMetadata","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"getContribution","outputs":[{"name":"id","type":"uint256"},{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"claimAfterBlock","type":"uint256"},{"name":"exists","type":"bool"},{"name":"vetoed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"},{"name":"contributorId","type":"uint256"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"add","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"veto","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"claim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index 2e33494..ae7e450 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -29,15 +29,33 @@ class Contribution extends Base { } - getByContributor(contributor) { - return this.functions.balanceOf(contributor) + getByContributorId(contributorId) { + return this.functions.balanceOf(address) then((balance) => { count = balance.toNumber(); let contributions = []; for (let index = 0; index <= count; index++) { - this.functions.tokenOfOwnerByIndex(contributor, index) + this.functions.tokenOfOwnerByIndex(address, index) + .then((id) => { + contributions.push(this.getById(id)); + }); + } + + return RSVP.all(contributions); + }); + } + + getByContributorAddress(address) { + return this.functions.balanceOf(address) + then((balance) => { + count = balance.toNumber(); + + let contributions = []; + + for (let index = 0; index <= count; index++) { + this.functions.tokenOfOwnerByIndex(address, index) .then((id) => { contributions.push(this.getById(id)); }); @@ -56,7 +74,7 @@ class Contribution extends Base { .then((ipfsHashAttr) => { let contribution = [ contributionAttr.amount, - contributionAttr.contributorAccount, + contributionAttr.contributorId, ipfsHashAttr.hashDigest, ipfsHashAttr.hashFunction, ipfsHashAttr.hashSize, From 197a31b9e1faeedc053a66a0b7da12e6546152b2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 14:47:25 +0200 Subject: [PATCH 02/13] Remove whitespace --- apps/token/contracts/Token.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/token/contracts/Token.sol b/apps/token/contracts/Token.sol index 2096d9c..877e494 100644 --- a/apps/token/contracts/Token.sol +++ b/apps/token/contracts/Token.sol @@ -9,9 +9,9 @@ contract Token is ERC20Token, AragonApp { // ensure alphabetic order enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; - + event LogMint(address indexed recipient, uint256 amount, uint256 contributionId); - + function initialize(bytes32[4] _appIds) public onlyInit { appIds = _appIds; initialized(); From 786f38cfb780ed7957ba4d62c96539c03c2993c9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 15:25:31 +0200 Subject: [PATCH 03/13] Print errors in seed contract calls --- scripts/seeds.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/seeds.js b/scripts/seeds.js index 15c5e6b..7115ae2 100644 --- a/scripts/seeds.js +++ b/scripts/seeds.js @@ -40,6 +40,7 @@ module.exports = async function(callback) { next(); }).catch((error) => { console.log(`[FAILED] kredits.${contractName}.${method}(${JSON.stringify(args)})`); + console.log(`Error: ${error.message}`); next(); }); }, () => { console.log("\nDone!") }); From f1e2c65b9e328fa4b77a74858372c192137527c7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 15:28:18 +0200 Subject: [PATCH 04/13] Use smaller numbers where appropriate --- apps/contribution/contracts/Contribution.sol | 61 ++++++++++---------- apps/token/contracts/Token.sol | 4 +- lib/abis/Contribution.json | 2 +- lib/abis/Token.json | 2 +- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/apps/contribution/contracts/Contribution.sol b/apps/contribution/contracts/Contribution.sol index 1717717..1985148 100644 --- a/apps/contribution/contracts/Contribution.sol +++ b/apps/contribution/contracts/Contribution.sol @@ -4,14 +4,14 @@ import "@aragon/os/contracts/apps/AragonApp.sol"; import "@aragon/os/contracts/kernel/IKernel.sol"; interface IToken { - function mintFor(address contributorAccount, uint256 amount, uint256 contributionId) public; + function mintFor(address contributorAccount, uint256 amount, uint32 contributionId) public; } interface ContributorInterface { - function getContributorAddressById(uint256 contributorId) public view returns (address); - function getContributorIdByAddress(address contributorAccount) public view returns (uint256); + function getContributorAddressById(uint32 contributorId) public view returns (address); + function getContributorIdByAddress(address contributorAccount) public view returns (uint32); // TODO Maybe use for validation - // function exists(uint256 contributorId) public view returns (bool); + // function exists(uint32 contributorId) public view returns (bool); } contract Contribution is AragonApp { @@ -25,8 +25,8 @@ contract Contribution is AragonApp { bytes32[4] public appIds; struct ContributionData { - uint256 contributorId; - uint256 amount; + uint32 contributorId; + uint32 amount; bool claimed; bytes32 hashDigest; uint8 hashFunction; @@ -41,18 +41,18 @@ contract Contribution is AragonApp { string internal symbol_; // map contribution ID to contributor - mapping(uint256 => uint256) public contributionOwner; + mapping(uint32 => uint32) public contributionOwner; // map contributor to contribution IDs - mapping(uint256 => uint256[]) public ownedContributions; + mapping(uint32 => uint32[]) public ownedContributions; - mapping(uint256 => ContributionData) public contributions; - uint256 public contributionsCount; + mapping(uint32 => ContributionData) public contributions; + uint32 public contributionsCount; - uint256 public blocksToWait = 0; + uint32 public blocksToWait = 0; - event ContributionAdded(uint256 id, uint256 indexed contributorId, uint256 amount); - event ContributionClaimed(uint256 id, uint256 indexed contributorId, uint256 amount); - event ContributionVetoed(uint256 id, address vetoedByAccount); + event ContributionAdded(uint32 id, uint32 indexed contributorId, uint32 amount); + event ContributionClaimed(uint32 id, uint32 indexed contributorId, uint32 amount); + event ContributionVetoed(uint32 id, address vetoedByAccount); function initialize(bytes32[4] _appIds) public onlyInit { appIds = _appIds; @@ -69,12 +69,12 @@ contract Contribution is AragonApp { return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contributor)]); } - function getContributorIdByAddress(address contributorAccount) public view returns (uint256) { + function getContributorIdByAddress(address contributorAccount) public view returns (uint32) { address contributor = getContributorContract(); return ContributorInterface(contributor).getContributorIdByAddress(contributorAccount); } - function getContributorAddressById(uint256 contributorId) public view returns (uint256) { + function getContributorAddressById(uint32 contributorId) public view returns (address) { address contributor = getContributorContract(); return ContributorInterface(contributor).getContributorAddressById(contributorId); } @@ -94,22 +94,22 @@ contract Contribution is AragonApp { // Balance is amount of ERC271 tokens, not amount of kredits function balanceOf(address owner) public view returns (uint256) { require(owner != address(0)); - uint256 contributorId = getContributorIdByAddress(owner); + uint32 contributorId = getContributorIdByAddress(owner); return ownedContributions[contributorId].length; } - function ownerOf(uint256 contributionId) public view returns (address) { + function ownerOf(uint32 contributionId) public view returns (address) { require(exists(contributionId)); - uint256 contributorId = contributions[contributionId].contributorId; + uint32 contributorId = contributions[contributionId].contributorId; return getContributorAddressById(contributorId); } - function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) { - uint256 contributorId = getContributorIdByAddress(owner); + function tokenOfOwnerByIndex(address owner, uint32 index) public view returns (uint32) { + uint32 contributorId = getContributorIdByAddress(owner); return ownedContributions[contributorId][index]; } - function tokenMetadata(uint256 contributionId) public view returns (string) { + function tokenMetadata(uint32 contributionId) public view returns (string) { return contributions[contributionId].tokenMetadataURL; } @@ -117,7 +117,7 @@ contract Contribution is AragonApp { // Custom functions // - function getContribution(uint256 contributionId) public view returns (uint256 id, uint256 contributorId, uint256 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint claimAfterBlock, bool exists, bool vetoed) { + function getContribution(uint32 contributionId) public view returns (uint32 id, uint32 contributorId, uint32 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint claimAfterBlock, bool exists, bool vetoed) { id = contributionId; ContributionData storage c = contributions[id]; return ( @@ -134,9 +134,9 @@ contract Contribution is AragonApp { ); } - function add(uint256 amount, uint256 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) { - //require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint256[](0)), 'nope'); - uint256 contributionId = contributionsCount + 1; + function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) { + //require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope'); + uint32 contributionId = contributionsCount + 1; ContributionData storage c = contributions[contributionId]; c.exists = true; c.amount = amount; @@ -155,7 +155,7 @@ contract Contribution is AragonApp { emit ContributionAdded(contributionId, contributorId, amount); } - function veto(uint256 contributionId) public isInitialized auth(VETO_CONTRIBUTION_ROLE) { + function veto(uint32 contributionId) public isInitialized auth(VETO_CONTRIBUTION_ROLE) { ContributionData storage c = contributions[contributionId]; require(c.exists, 'NOT_FOUND'); require(!c.claimed, 'ALREADY_CLAIMED'); @@ -164,7 +164,7 @@ contract Contribution is AragonApp { emit ContributionVetoed(contributionId, msg.sender); } - function claim(uint256 contributionId) public isInitialized { + function claim(uint32 contributionId) public isInitialized { ContributionData storage c = contributions[contributionId]; require(c.exists, 'NOT_FOUND'); require(!c.claimed, 'ALREADY_CLAIMED'); @@ -174,11 +174,12 @@ contract Contribution is AragonApp { c.claimed = true; address token = getTokenContract(); address contributorAccount = getContributorAddressById(c.contributorId); - IToken(token).mintFor(contributorAccount, c.amount, contributionId); + uint256 amount = uint256(c.amount); + IToken(token).mintFor(contributorAccount, amount, contributionId); emit ContributionClaimed(contributionId, c.contributorId, c.amount); } - function exists(uint256 contributionId) view public returns (bool) { + function exists(uint32 contributionId) view public returns (bool) { return contributions[contributionId].exists; } } diff --git a/apps/token/contracts/Token.sol b/apps/token/contracts/Token.sol index 877e494..098c7de 100644 --- a/apps/token/contracts/Token.sol +++ b/apps/token/contracts/Token.sol @@ -10,14 +10,14 @@ contract Token is ERC20Token, AragonApp { enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; - event LogMint(address indexed recipient, uint256 amount, uint256 contributionId); + event LogMint(address indexed recipient, uint256 amount, uint32 contributionId); function initialize(bytes32[4] _appIds) public onlyInit { appIds = _appIds; initialized(); } - function mintFor(address contributorAccount, uint256 amount, uint256 contributionId) public isInitialized auth(MINT_TOKEN_ROLE) { + function mintFor(address contributorAccount, uint256 amount, uint32 contributionId) public isInitialized auth(MINT_TOKEN_ROLE) { _mint(contributorAccount, amount); emit LogMint(contributorAccount, amount, contributionId); } diff --git a/lib/abis/Contribution.json b/lib/abis/Contribution.json index d2ae07f..0a83fae 100644 --- a/lib/abis/Contribution.json +++ b/lib/abis/Contribution.json @@ -1 +1 @@ -[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributions","outputs":[{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"tokenMetadataURL","type":"string"},{"name":"claimAfterBlock","type":"uint256"},{"name":"vetoed","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributionsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"ownedContributions","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"blocksToWait","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VETO_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributionOwner","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":true,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ContributionClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"vetoedByAccount","type":"address"}],"name":"ContributionVetoed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getContributorContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorAccount","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorId","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"tokenMetadata","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"getContribution","outputs":[{"name":"id","type":"uint256"},{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"claimAfterBlock","type":"uint256"},{"name":"exists","type":"bool"},{"name":"vetoed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"},{"name":"contributorId","type":"uint256"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"add","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"veto","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"claim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributionsCount","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"contributionOwner","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"contributions","outputs":[{"name":"contributorId","type":"uint32"},{"name":"amount","type":"uint32"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"tokenMetadataURL","type":"string"},{"name":"claimAfterBlock","type":"uint256"},{"name":"vetoed","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"},{"name":"","type":"uint256"}],"name":"ownedContributions","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"blocksToWait","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VETO_CONTRIBUTION_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":true,"name":"contributorId","type":"uint32"},{"indexed":false,"name":"amount","type":"uint32"}],"name":"ContributionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":true,"name":"contributorId","type":"uint32"},{"indexed":false,"name":"amount","type":"uint32"}],"name":"ContributionClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"vetoedByAccount","type":"address"}],"name":"ContributionVetoed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getContributorContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorAccount","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributorId","type":"uint32"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"index","type":"uint32"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"tokenMetadata","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"getContribution","outputs":[{"name":"id","type":"uint32"},{"name":"contributorId","type":"uint32"},{"name":"amount","type":"uint32"},{"name":"claimed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"claimAfterBlock","type":"uint256"},{"name":"exists","type":"bool"},{"name":"vetoed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint32"},{"name":"contributorId","type":"uint32"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"add","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"veto","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"claim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"contributionId","type":"uint32"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/lib/abis/Token.json b/lib/abis/Token.json index c2d8ea0..55f0801 100644 --- a/lib/abis/Token.json +++ b/lib/abis/Token.json @@ -1 +1 @@ -[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"_totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"_balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MINT_TOKEN_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"contributionId","type":"uint256"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributorAccount","type":"address"},{"name":"amount","type":"uint256"},{"name":"contributionId","type":"uint256"}],"name":"mintFor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"_totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"_balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MINT_TOKEN_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"contributionId","type":"uint32"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributorAccount","type":"address"},{"name":"amount","type":"uint256"},{"name":"contributionId","type":"uint32"}],"name":"mintFor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file From 6088f30cd8cf3e435619f0f9a682bed95fe2cf0d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 16:01:08 +0200 Subject: [PATCH 05/13] Use smaller numbers for contributor ID 2.2 billion contributors should be enough. --- apps/contributor/contracts/Contributor.sol | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/contributor/contracts/Contributor.sol b/apps/contributor/contracts/Contributor.sol index d7cc99a..16f0f66 100644 --- a/apps/contributor/contracts/Contributor.sol +++ b/apps/contributor/contracts/Contributor.sol @@ -20,20 +20,20 @@ contract Contributor is AragonApp { bool exists; } - mapping (address => uint256) public contributorIds; - mapping (uint256 => Contributor) public contributors; - uint256 public contributorsCount; + mapping (address => uint32) public contributorIds; + mapping (uint32 => Contributor) public contributors; + uint32 public contributorsCount; // ensure alphabetic order enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; - event ContributorProfileUpdated(uint256 id, bytes32 oldIpfsHash, bytes32 newIpfsHash); - event ContributorAccountUpdated(uint256 id, address oldAccount, address newAccount); - event ContributorAdded(uint256 id, address account); + event ContributorProfileUpdated(uint32 id, bytes32 oldIpfsHash, bytes32 newIpfsHash); + event ContributorAccountUpdated(uint32 id, address oldAccount, address newAccount); + event ContributorAdded(uint32 id, address account); function initialize(address root,bytes32[4] _appIds) public onlyInit { - uint256 _id = contributorsCount + 1; + uint32 _id = contributorsCount + 1; Contributor storage c = contributors[_id]; c.exists = true; c.isCore = true; @@ -52,9 +52,9 @@ contract Contributor is AragonApp { return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]); } - function coreContributorsCount() view public returns (uint256) { - uint256 count = 0; - for (uint256 i = 1; i <= contributorsCount; i++) { + function coreContributorsCount() view public returns (uint32) { + uint32 count = 0; + for (uint32 i = 1; i <= contributorsCount; i++) { if (contributors[i].isCore) { count += 1; } @@ -62,14 +62,14 @@ contract Contributor is AragonApp { return count; } - function updateContributorAccount(uint256 id, address oldAccount, address newAccount) public auth(MANAGE_CONTRIBUTORS_ROLE) { + function updateContributorAccount(uint32 id, address oldAccount, address newAccount) public auth(MANAGE_CONTRIBUTORS_ROLE) { contributorIds[oldAccount] = 0; contributorIds[newAccount] = id; contributors[id].account = newAccount; ContributorAccountUpdated(id, oldAccount, newAccount); } - function updateContributorIpfsHash(uint256 id, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) { + function updateContributorIpfsHash(uint32 id, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) { Contributor storage c = contributors[id]; bytes32 oldIpfsHash = c.ipfsHash; c.ipfsHash = ipfsHash; @@ -81,7 +81,7 @@ contract Contributor is AragonApp { function addContributor(address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore) public isInitialized auth(MANAGE_CONTRIBUTORS_ROLE) { require(!addressExists(account)); - uint256 _id = contributorsCount + 1; + uint32 _id = contributorsCount + 1; assert(!contributors[_id].exists); // this can not be acually Contributor storage c = contributors[_id]; c.exists = true; @@ -96,11 +96,11 @@ contract Contributor is AragonApp { emit ContributorAdded(_id, account); } - function isCore(uint256 id) view public returns (bool) { + function isCore(uint32 id) view public returns (bool) { return contributors[id].isCore; } - function exists(uint256 id) view public returns (bool) { + function exists(uint32 id) view public returns (bool) { return contributors[id].exists; } @@ -112,20 +112,20 @@ contract Contributor is AragonApp { return getContributorByAddress(account).exists; } - function getContributorIdByAddress(address account) view public returns (uint256) { + function getContributorIdByAddress(address account) view public returns (uint32) { return contributorIds[account]; } - function getContributorAddressById(uint256 id) view public returns (address) { + function getContributorAddressById(uint32 id) view public returns (address) { return contributors[id].account; } function getContributorByAddress(address account) internal view returns (Contributor) { - uint256 id = contributorIds[account]; + uint32 id = contributorIds[account]; return contributors[id]; } - function getContributorById(uint256 _id) public view returns (uint256 id, address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, bool exists ) { + function getContributorById(uint32 _id) public view returns (uint32 id, address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, bool exists ) { id = _id; Contributor storage c = contributors[_id]; account = c.account; @@ -138,14 +138,14 @@ contract Contributor is AragonApp { exists = c.exists; } - function canPerform(address _who, address _where, bytes32 _what, uint256[] memory _how) public returns (bool) { + function canPerform(address _who, address _where, bytes32 _what/*, uint256[] memory _how*/) public returns (bool) { address sender = _who; if (sender == address(-1)) { sender = tx.origin; } // _what == keccak256('VOTE_PROPOSAL_ROLE') if (_what == 0xd61216798314d2fc33e42ff2021d66707b1e38517d3f7166798a9d3a196a9c96) { - return contributorIds[sender] != uint256(0); + return contributorIds[sender] != uint256(0); } return addressIsCore(sender); From 5b49f825445fc21aac3341e17336bb3058354655 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 16:24:23 +0200 Subject: [PATCH 06/13] Adjust wrapper and scripts for contract changes --- lib/contracts/contribution.js | 37 ++++++++++++++++------------------- lib/contracts/contributor.js | 5 +---- scripts/add-contribution.js | 2 +- scripts/list-contributions.js | 3 +-- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index ae7e450..68e0975 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -7,8 +7,7 @@ const Base = require('./base'); class Contribution extends Base { all() { return this.functions.contributionsCount() - .then((count) => { - count = count.toNumber(); + .then(count => { let contributions = []; for (let id = 1; id <= count; id++) { @@ -20,31 +19,29 @@ class Contribution extends Base { } getById(id) { - id = ethers.utils.bigNumberify(id); - return this.functions.getContribution(id) - .then((data) => { + .then(data => { return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); }); } getByContributorId(contributorId) { - return this.functions.balanceOf(address) - then((balance) => { - count = balance.toNumber(); - - let contributions = []; - - for (let index = 0; index <= count; index++) { - this.functions.tokenOfOwnerByIndex(address, index) - .then((id) => { - contributions.push(this.getById(id)); - }); - } - - return RSVP.all(contributions); - }); + // return this.functions.balanceOf(address) + // then(balance => { + // count = balance.toNumber(); + // + // let contributions = []; + // + // for (let index = 0; index <= count; index++) { + // this.functions.tokenOfOwnerByIndex(address, index) + // .then((id) => { + // contributions.push(this.getById(id)); + // }); + // } + // + // return RSVP.all(contributions); + // }); } getByContributorAddress(address) { diff --git a/lib/contracts/contributor.js b/lib/contracts/contributor.js index b122c20..029f7ef 100644 --- a/lib/contracts/contributor.js +++ b/lib/contracts/contributor.js @@ -7,8 +7,7 @@ const Base = require('./base'); class Contributor extends Base { all() { return this.functions.contributorsCount() - .then((count) => { - count = count.toNumber(); + .then(count => { let contributors = []; for (let id = 1; id <= count; id++) { @@ -20,8 +19,6 @@ class Contributor extends Base { } getById(id) { - id = ethers.utils.bigNumberify(id); - return this.functions.getContributorById(id) .then((data) => { // TODO: remove when naming updated on the contract diff --git a/scripts/add-contribution.js b/scripts/add-contribution.js index 8a6d84b..7b1e448 100644 --- a/scripts/add-contribution.js +++ b/scripts/add-contribution.js @@ -27,7 +27,7 @@ module.exports = async function(callback) { console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`); let contributionAttributes = { - contributorAccount, + contributorId, amount: await promptly.prompt('Amount: '), description: await promptly.prompt('Description: '), kind: await promptly.prompt('Kind: ', { default: 'dev' }), diff --git a/scripts/list-contributions.js b/scripts/list-contributions.js index 28e1734..cc2652a 100644 --- a/scripts/list-contributions.js +++ b/scripts/list-contributions.js @@ -14,7 +14,6 @@ module.exports = async function(callback) { console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`); - const table = new Table({ head: ['ID', 'Contributor account', 'Amount', 'Claimed?', 'Vetoed?', 'Description'] }) @@ -24,7 +23,7 @@ module.exports = async function(callback) { contributions.forEach((c) => { table.push([ c.id.toString(), - c.contributor, + c.contributorId, c.amount.toString(), c.claimed, c.vetoed, From e4c3d9a468e0bdcdce7a3dfc71fe6caa988ccec6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 16:28:34 +0200 Subject: [PATCH 07/13] Update abi --- lib/abis/Contributor.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/abis/Contributor.json b/lib/abis/Contributor.json index 514f692..82542e8 100644 --- a/lib/abis/Contributor.json +++ b/lib/abis/Contributor.json @@ -1 +1 @@ -[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributors","outputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"contributorIds","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MANAGE_CONTRIBUTORS_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldIpfsHash","type":"bytes32"},{"indexed":false,"name":"newIpfsHash","type":"bytes32"}],"name":"ContributorProfileUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldAccount","type":"address"},{"indexed":false,"name":"newAccount","type":"address"}],"name":"ContributorAccountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"account","type":"address"}],"name":"ContributorAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"root","type":"address"},{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"oldAccount","type":"address"},{"name":"newAccount","type":"address"}],"name":"updateContributorAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"updateContributorIpfsHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"isCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressIsCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressExists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributorById","outputs":[{"name":"id","type":"uint256"},{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"balance","type":"uint256"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"},{"name":"_where","type":"address"},{"name":"_what","type":"bytes32"},{"name":"_how","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"contributorIds","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MANAGE_CONTRIBUTORS_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"contributors","outputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"oldIpfsHash","type":"bytes32"},{"indexed":false,"name":"newIpfsHash","type":"bytes32"}],"name":"ContributorProfileUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"oldAccount","type":"address"},{"indexed":false,"name":"newAccount","type":"address"}],"name":"ContributorAccountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"account","type":"address"}],"name":"ContributorAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"root","type":"address"},{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint32"},{"name":"oldAccount","type":"address"},{"name":"newAccount","type":"address"}],"name":"updateContributorAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint32"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"updateContributorIpfsHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint32"}],"name":"isCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint32"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressIsCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressExists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint32"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint32"}],"name":"getContributorById","outputs":[{"name":"id","type":"uint32"},{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"balance","type":"uint256"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"},{"name":"_where","type":"address"},{"name":"_what","type":"bytes32"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file From a1a1c5ef9f0a8b6d6461ff3198e08abdd2799b4f Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Thu, 4 Apr 2019 22:29:37 +0200 Subject: [PATCH 08/13] Get contributor by ID Co-Authored-By: skddc --- lib/contracts/contribution.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index 68e0975..dd6fe6d 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -27,6 +27,9 @@ class Contribution extends Base { } getByContributorId(contributorId) { + return this.functions.getContributorAddressById(contributorId) + .then(address => this.getByContributorAddress(address)); + } // return this.functions.balanceOf(address) // then(balance => { // count = balance.toNumber(); From 19556349f69d85bd2f45b4afa02966213251fb10 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 22:30:10 +0200 Subject: [PATCH 09/13] Fix syntax error --- lib/contracts/contribution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index dd6fe6d..cad029d 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -49,7 +49,7 @@ class Contribution extends Base { getByContributorAddress(address) { return this.functions.balanceOf(address) - then((balance) => { + .then((balance) => { count = balance.toNumber(); let contributions = []; From 181e6f3c23e98ed93d81bb47048fb36d58a13047 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 22:56:06 +0200 Subject: [PATCH 10/13] Fix/refactor contribution wrapper --- lib/contracts/contribution.js | 42 ++++++++++------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index cad029d..780049d 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -1,5 +1,4 @@ const ethers = require('ethers'); -const RSVP = require('rsvp'); const ContributionSerializer = require('../serializers/contribution'); const Base = require('./base'); @@ -7,14 +6,15 @@ const Base = require('./base'); class Contribution extends Base { all() { return this.functions.contributionsCount() - .then(count => { + .then(async (count) => { let contributions = []; for (let id = 1; id <= count; id++) { - contributions.push(this.getById(id)); + const contribution = await this.getById(id) + contributions.push(contribution); } - return RSVP.all(contributions); + return contributions; }); } @@ -30,38 +30,20 @@ class Contribution extends Base { return this.functions.getContributorAddressById(contributorId) .then(address => this.getByContributorAddress(address)); } - // return this.functions.balanceOf(address) - // then(balance => { - // count = balance.toNumber(); - // - // let contributions = []; - // - // for (let index = 0; index <= count; index++) { - // this.functions.tokenOfOwnerByIndex(address, index) - // .then((id) => { - // contributions.push(this.getById(id)); - // }); - // } - // - // return RSVP.all(contributions); - // }); - } getByContributorAddress(address) { return this.functions.balanceOf(address) - .then((balance) => { - count = balance.toNumber(); + .then(async (balance) => { + const count = balance.toNumber(); + const contributions = []; - let contributions = []; - - for (let index = 0; index <= count; index++) { - this.functions.tokenOfOwnerByIndex(address, index) - .then((id) => { - contributions.push(this.getById(id)); - }); + for (let index = 0; index < count; index++) { + const id = await this.functions.tokenOfOwnerByIndex(address, index); + const contribution = await this.getById(id); + contributions.push(contribution); } - return RSVP.all(contributions); + return contributions; }); } From a049f2eedbb1ca7898d21e69b7c10211eb2ebcfd Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 23:11:43 +0200 Subject: [PATCH 11/13] Adjust proposals for format changes --- apps/proposal/contracts/Proposal.sol | 63 ++++++++++++++-------------- lib/contracts/proposal.js | 7 +--- scripts/list-proposals.js | 1 - 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/apps/proposal/contracts/Proposal.sol b/apps/proposal/contracts/Proposal.sol index a0d808f..de89a51 100644 --- a/apps/proposal/contracts/Proposal.sol +++ b/apps/proposal/contracts/Proposal.sol @@ -4,13 +4,13 @@ import "@aragon/os/contracts/apps/AragonApp.sol"; import "@aragon/os/contracts/kernel/IKernel.sol"; interface IContributor { - function getContributorAddressById(uint256 contributorId) public view returns (address); - function getContributorIdByAddress(address contributorAccount) public view returns (uint256); - function exists(uint256 contributorId) public view returns (bool); + function getContributorAddressById(uint32 contributorId) public view returns (address); + function getContributorIdByAddress(address contributorAccount) public view returns (uint32); + function exists(uint32 contributorId) public view returns (bool); } interface IContribution { - function add(uint256 amount, address contributor, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public; + function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public; } contract Proposal is AragonApp { @@ -25,26 +25,26 @@ contract Proposal is AragonApp { struct Proposal { address creatorAccount; - uint contributorId; - uint votesCount; - uint votesNeeded; - uint256 amount; + uint32 contributorId; + uint16 votesCount; + uint16 votesNeeded; + uint32 amount; bool executed; bytes32 hashDigest; uint8 hashFunction; uint8 hashSize; - uint256[] voterIds; - mapping (uint256 => bool) votes; + uint32[] voterIds; + mapping (uint32 => bool) votes; bool exists; } - mapping(uint256 => Proposal) public proposals; - uint256 public proposalsCount; + mapping(uint32 => Proposal) public proposals; + uint32 public proposalsCount; - event ProposalCreated(uint256 id, address creatorAccount, uint256 contributorId, uint256 amount); + event ProposalCreated(uint32 id, address creatorAccount, uint32 contributorId, uint32 amount); - event ProposalVoted(uint256 id, uint256 voterId, uint256 totalVotes); - event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount); + event ProposalVoted(uint32 id, uint32 voterId, uint16 totalVotes); + event ProposalExecuted(uint32 id, uint32 contributorId, uint32 amount); function initialize(bytes32[4] _appIds) public onlyInit { appIds = _appIds; @@ -59,11 +59,11 @@ contract Proposal is AragonApp { return IKernel(kernel()).getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]); } - function addProposal(uint contributorId, uint256 amount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_PROPOSAL_ROLE) { + function addProposal(uint32 contributorId, uint32 amount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_PROPOSAL_ROLE) { require(IContributor(getContributorContract()).exists(contributorId), 'CONTRIBUTOR_NOT_FOUND'); - uint256 proposalId = proposalsCount + 1; - uint256 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75; + uint32 proposalId = proposalsCount + 1; + uint16 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75; Proposal storage p = proposals[proposalId]; p.creatorAccount = msg.sender; @@ -75,23 +75,23 @@ contract Proposal is AragonApp { p.votesCount = 0; p.votesNeeded = _votesNeeded; p.exists = true; - + proposalsCount++; emit ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount); } - function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 contributorId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + function getProposal(uint32 proposalId) public view returns (uint32 id, address creatorAccount, uint32 contributorId, uint16 votesCount, uint16 votesNeeded, uint32 amount, bool executed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint32[] voterIds, bool exists) { id = proposalId; Proposal storage p = proposals[id]; return ( id, p.creatorAccount, - p.contributorId, - p.votesCount, + p.contributorId, + p.votesCount, p.votesNeeded, p.amount, - p.executed, - p.hashDigest, + p.executed, + p.hashDigest, p.hashFunction, p.hashSize, p.voterIds, @@ -99,10 +99,10 @@ contract Proposal is AragonApp { ); } - function vote(uint256 proposalId) public isInitialized auth(VOTE_PROPOSAL_ROLE) { + function vote(uint32 proposalId) public isInitialized auth(VOTE_PROPOSAL_ROLE) { Proposal storage p = proposals[proposalId]; require(!p.executed, 'ALREADY_EXECUTED'); - uint256 voterId = IContributor(getContributorContract()).getContributorIdByAddress(msg.sender); + uint32 voterId = IContributor(getContributorContract()).getContributorIdByAddress(msg.sender); require(p.votes[voterId] != true, 'ALREADY_VOTED'); p.voterIds.push(voterId); p.votes[voterId] = true; @@ -114,20 +114,19 @@ contract Proposal is AragonApp { emit ProposalVoted(proposalId, voterId, p.votesCount); } - function batchVote(uint256[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) { - for (uint256 i = 0; i < _proposalIds.length; i++) { + function batchVote(uint32[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) { + for (uint32 i = 0; i < _proposalIds.length; i++) { vote(_proposalIds[i]); } } - function executeProposal(uint proposalId) private { + function executeProposal(uint32 proposalId) private { Proposal storage p = proposals[proposalId]; require(!p.executed, 'ALREADY_EXECUTED'); require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES'); - + p.executed = true; - address contributorAccount = IContributor(getContributorContract()).getContributorAddressById(p.contributorId); - IContribution(getContributionContract()).add(p.amount, contributorAccount, p.hashDigest, p.hashFunction, p.hashSize); + IContribution(getContributionContract()).add(p.amount, p.contributorId, p.hashDigest, p.hashFunction, p.hashSize); emit ProposalExecuted(proposalId, p.contributorId, p.amount); } diff --git a/lib/contracts/proposal.js b/lib/contracts/proposal.js index cf7e363..896b72f 100644 --- a/lib/contracts/proposal.js +++ b/lib/contracts/proposal.js @@ -7,8 +7,7 @@ const Base = require('./base'); class Proposal extends Base { all() { return this.functions.proposalsCount() - .then((count) => { - count = count.toNumber(); + .then(count => { let proposals = []; for (let id = 1; id <= count; id++) { @@ -20,10 +19,8 @@ class Proposal extends Base { } getById(id) { - id = ethers.utils.bigNumberify(id); - return this.functions.getProposal(id) - .then((data) => { + .then(data => { return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); }); } diff --git a/scripts/list-proposals.js b/scripts/list-proposals.js index 701ce83..2bbbedf 100644 --- a/scripts/list-proposals.js +++ b/scripts/list-proposals.js @@ -14,7 +14,6 @@ module.exports = async function(callback) { console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`); - const table = new Table({ head: ['ID', 'Contributor ID', 'Amount', 'Votes', 'Executed?', 'Description'] }) From d507d7b56263d463fbfa2f0ac27af2840b308f33 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 23:16:01 +0200 Subject: [PATCH 12/13] Enable all seeds again --- config/seeds.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/seeds.js b/config/seeds.js index a6d0562..49654bc 100644 --- a/config/seeds.js +++ b/config/seeds.js @@ -1,10 +1,10 @@ const contractCalls = [ ['Contributor', 'add', [{ account: '0x7e8f313c56f809188313aa274fa67ee58c31515d', name: 'bumi', isCore: true, kind: 'person', url: '', github_username: 'bumi', github_uid: 318, wiki_username: 'bumi' }, { gasLimit: 200000 }]], ['Contributor', 'add', [{ account: '0x49575f3DD9a0d60aE661BC992f72D837A77f05Bc', name: 'raucao', isCore: true, kind: 'person', url: '', github_username: 'skddc', github_uid: 842, wiki_username: 'raucau' }, { gasLimit: 200000 }]], - // ['Proposal', 'addProposal', [{ contributorId: 2, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], - // ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], - // ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Hacked on kredits', url: '' }, { gasLimit: 350000 }]], - // ['Proposal', 'vote', [1, { gasLimit: 550000 }]], + ['Proposal', 'addProposal', [{ contributorId: 2, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], + ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Ran the seeds', url: '' }, { gasLimit: 350000 }]], + ['Proposal', 'addProposal', [{ contributorId: 3, amount: 500, kind: 'code', description: '[67P/kredits-contracts] Hacked on kredits', url: '' }, { gasLimit: 350000 }]], + ['Proposal', 'vote', [1, { gasLimit: 550000 }]], ['Contribution', 'addContribution', [{ contributorId: 2, amount: 5000, kind: 'dev', description: '[67P/kredits-contracts] Introduce contribution token', url: '' }, { gasLimit: 350000 }]], ['Contribution', 'addContribution', [{ contributorId: 3, amount: 1500, kind: 'dev', description: '[67P/kredits-web] Reviewed stuff', url: '' }, { gasLimit: 350000 }]], ['Contribution', 'claim', [1, { gasLimit: 300000 }]] From 896db5e04703ecacadbccd053a7fff1f39725562 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 4 Apr 2019 23:16:23 +0200 Subject: [PATCH 13/13] Update abi --- lib/abis/Proposal.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/abis/Proposal.json b/lib/abis/Proposal.json index ec996c9..9467f53 100644 --- a/lib/abis/Proposal.json +++ b/lib/abis/Proposal.json @@ -1 +1 @@ -[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VOTE_PROPOSAL_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_PROPOSAL_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"creatorAccount","type":"address"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"voterId","type":"uint256"},{"indexed":false,"name":"totalVotes","type":"uint256"}],"name":"ProposalVoted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getContributorContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getContributionContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"addProposal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"getProposal","outputs":[{"name":"id","type":"uint256"},{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"voterIds","type":"uint256[]"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_proposalIds","type":"uint256[]"}],"name":"batchVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"hasInitialized","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalsCount","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_script","type":"bytes"}],"name":"getEVMScriptExecutor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"proposals","outputs":[{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint32"},{"name":"votesCount","type":"uint16"},{"name":"votesNeeded","type":"uint16"},{"name":"amount","type":"uint32"},{"name":"executed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRecoveryVault","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"VOTE_PROPOSAL_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"token","type":"address"}],"name":"allowRecoverability","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getInitializationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KERNEL_APP_ADDR_NAMESPACE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"transferToVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_role","type":"bytes32"},{"name":"_params","type":"uint256[]"}],"name":"canPerform","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEVMScriptRegistry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPetrified","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"appIds","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ADD_PROPOSAL_ROLE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"creatorAccount","type":"address"},{"indexed":false,"name":"contributorId","type":"uint32"},{"indexed":false,"name":"amount","type":"uint32"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"voterId","type":"uint32"},{"indexed":false,"name":"totalVotes","type":"uint16"}],"name":"ProposalVoted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint32"},{"indexed":false,"name":"contributorId","type":"uint32"},{"indexed":false,"name":"amount","type":"uint32"}],"name":"ProposalExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"executor","type":"address"},{"indexed":false,"name":"script","type":"bytes"},{"indexed":false,"name":"input","type":"bytes"},{"indexed":false,"name":"returnData","type":"bytes"}],"name":"ScriptResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"vault","type":"address"},{"indexed":true,"name":"token","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"RecoverToVault","type":"event"},{"constant":false,"inputs":[{"name":"_appIds","type":"bytes32[4]"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getContributorContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getContributionContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"contributorId","type":"uint32"},{"name":"amount","type":"uint32"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"addProposal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"proposalId","type":"uint32"}],"name":"getProposal","outputs":[{"name":"id","type":"uint32"},{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint32"},{"name":"votesCount","type":"uint16"},{"name":"votesNeeded","type":"uint16"},{"name":"amount","type":"uint32"},{"name":"executed","type":"bool"},{"name":"hashDigest","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"voterIds","type":"uint32[]"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"proposalId","type":"uint32"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_proposalIds","type":"uint32[]"}],"name":"batchVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file