Add contract calls for total contribution balances #110
@ -118,6 +118,26 @@ contract Contribution is AragonApp {
|
||||
// Custom functions
|
||||
//
|
||||
|
||||
function totalKreditsEarned(bool confirmedOnly) public view returns (uint256 count) {
|
||||
for (uint32 i = 1; i <= contributionsCount; i++) {
|
||||
ContributionData memory c = contributions[i];
|
||||
if (block.number >= c.confirmedAtBlock || !confirmedOnly) {
|
||||
count += c.amount; // should use safemath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint256 count) {
|
||||
uint256 tokenBalance = ownedContributions[contributorId].length;
|
||||
for (uint256 i = 0; i < tokenBalance; i++) {
|
||||
uint32 cId = ownedContributions[contributorId][i];
|
||||
ContributionData memory c = contributions[cId];
|
||||
if (block.number >= c.confirmedAtBlock || !confirmedOnly) {
|
||||
count += c.amount; // should use safemath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContribution(uint32 contributionId) public view returns (uint32 id, uint32 contributorId, uint32 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool exists, bool vetoed) {
|
||||
id = contributionId;
|
||||
ContributionData storage c = contributions[id];
|
||||
|
@ -6,6 +6,10 @@ import "@aragon/os/contracts/kernel/IKernel.sol";
|
||||
interface ITokenBalance {
|
||||
function balanceOf(address contributorAccount) public view returns (uint256);
|
||||
}
|
||||
interface IContributionBalance {
|
||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint256 count);
|
||||
function balanceOf(address owner) public view returns (uint256);
|
||||
}
|
||||
|
||||
contract Contributor is AragonApp {
|
||||
bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;
|
||||
@ -43,6 +47,12 @@ contract Contributor is AragonApp {
|
||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]);
|
||||
}
|
||||
|
||||
function getContributionContract() public view returns (address) {
|
||||
IKernel k = IKernel(kernel());
|
||||
|
||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]);
|
||||
}
|
||||
|
||||
function coreContributorsCount() view public returns (uint32) {
|
||||
uint32 count = 0;
|
||||
for (uint32 i = 1; i <= contributorsCount; i++) {
|
||||
@ -118,7 +128,7 @@ contract Contributor is AragonApp {
|
||||
return contributors[id];
|
||||
}
|
||||
|
||||
function getContributorById(uint32 _id) public view returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, bool exists ) {
|
||||
function getContributorById(uint32 _id) public view returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, uint256 totalKreditsEarned, uint256 contributionsCount, bool exists ) {
|
||||
id = _id;
|
||||
Contributor storage c = contributors[_id];
|
||||
account = c.account;
|
||||
@ -128,6 +138,9 @@ contract Contributor is AragonApp {
|
||||
isCore = isCoreTeam(id);
|
||||
address token = getTokenContract();
|
||||
balance = ITokenBalance(token).balanceOf(c.account);
|
||||
address contribution = getContributionContract();
|
||||
totalKreditsEarned = IContributionBalance(contribution).totalKreditsEarnedByContributor(_id, true);
|
||||
contributionsCount = IContributionBalance(contribution).balanceOf(c.account);
|
||||
exists = c.exists;
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -22,6 +22,7 @@ module.exports = async function(callback) {
|
||||
let blockNumber = await kredits.provider.getBlockNumber();
|
||||
let contributions = await kredits.Contribution.all();
|
||||
|
||||
console.log(`Current block number: ${blockNumber}`);
|
||||
contributions.forEach((c) => {
|
||||
const confirmed = c.confirmedAtBlock <= blockNumber;
|
||||
|
||||
@ -30,7 +31,7 @@ module.exports = async function(callback) {
|
||||
c.contributorId,
|
||||
`${c.description}`,
|
||||
c.amount.toString(),
|
||||
confirmed,
|
||||
`${confirmed} (${c.confirmedAtBlock})`,
|
||||
c.vetoed,
|
||||
c.claimed,
|
||||
c.ipfsHash
|
||||
@ -38,6 +39,9 @@ module.exports = async function(callback) {
|
||||
});
|
||||
|
||||
console.log(table.toString());
|
||||
|
||||
let totalContributionBalances = await kredits.Contribution.functions.totalCount(true);
|
||||
console.log(`Total confirmed balance: ${totalContributionBalances}`);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ module.exports = async function(callback) {
|
||||
|
||||
|
||||
const table = new Table({
|
||||
head: ['ID', 'Account', 'Name', 'Core?', 'Balance', 'IPFS']
|
||||
head: ['ID', 'Account', 'Name', 'Core?', 'Balance', 'Kredits earned', 'Contributions count', 'IPFS']
|
||||
})
|
||||
|
||||
let contributors = await kredits.Contributor.all()
|
||||
@ -29,6 +29,8 @@ module.exports = async function(callback) {
|
||||
`${c.name}`,
|
||||
c.isCore,
|
||||
ethers.utils.formatEther(c.balance),
|
||||
c.totalKreditsEarned.toString(),
|
||||
c.contributionsCount.toString(),
|
||||
c.ipfsHash
|
||||
])
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user