Add balance when loading contributor #67

Merged
bumi merged 2 commits from feature/contributor-balance-1 into master 2019-04-03 18:22:51 +00:00
3 changed files with 19 additions and 4 deletions

View File

@ -1,8 +1,14 @@
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "@aragon/os/contracts/apps/AragonApp.sol"; import "@aragon/os/contracts/apps/AragonApp.sol";
import "@aragon/os/contracts/kernel/IKernel.sol";
interface ITokenBalance {
function balanceOf(address contributorAccount) public view returns (uint256);
}
contract Contributor is AragonApp { contract Contributor is AragonApp {
bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;
bytes32 public constant MANAGE_CONTRIBUTORS_ROLE = keccak256("MANAGE_CONTRIBUTORS_ROLE"); bytes32 public constant MANAGE_CONTRIBUTORS_ROLE = keccak256("MANAGE_CONTRIBUTORS_ROLE");
struct Contributor { struct Contributor {
@ -40,6 +46,12 @@ contract Contributor is AragonApp {
initialized(); initialized();
} }
function getTokenContract() public view returns (address) {
IKernel k = IKernel(kernel());
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]);
}
function coreContributorsCount() view public returns (uint256) { function coreContributorsCount() view public returns (uint256) {
uint256 count = 0; uint256 count = 0;
for (uint256 i = 1; i <= contributorsCount; i++) { for (uint256 i = 1; i <= contributorsCount; i++) {
@ -113,7 +125,7 @@ contract Contributor is AragonApp {
return contributors[id]; return contributors[id];
} }
function getContributorById(uint256 _id) public view returns (uint256 id, address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore, bool exists ) { function getContributorById(uint256 _id) public view returns (uint256 id, address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, bool exists ) {
id = _id; id = _id;
Contributor storage c = contributors[_id]; Contributor storage c = contributors[_id];
account = c.account; account = c.account;
@ -121,6 +133,8 @@ contract Contributor is AragonApp {
hashFunction = c.hashFunction; hashFunction = c.hashFunction;
hashSize = c.hashSize; hashSize = c.hashSize;
isCore = c.isCore; isCore = c.isCore;
address token = getTokenContract();
balance = ITokenBalance(token).balanceOf(c.account);
exists = c.exists; exists = c.exists;
} }

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@ module.exports = async function(callback) {
const table = new Table({ const table = new Table({
head: ['ID', 'Account', 'Core?', 'Name'] head: ['ID', 'Account', 'Core?', 'Name', 'Balance']
}) })
let contributors = await kredits.Contributor.all() let contributors = await kredits.Contributor.all()
@ -26,7 +26,8 @@ module.exports = async function(callback) {
c.id.toString(), c.id.toString(),
c.account, c.account,
c.isCore, c.isCore,
`${c.name}` `${c.name}`,
c.balance.toString()
]) ])
}) })
console.log(table.toString()) console.log(table.toString())