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,