Add contract calls for total contribution balances
Those methods return the total kredits amounts of contribtions.
This commit is contained in:
parent
5820d71b2c
commit
59135bf312
@ -118,6 +118,26 @@ contract Contribution is AragonApp {
|
|||||||
// Custom functions
|
// Custom functions
|
||||||
//
|
//
|
||||||
|
|
||||||
|
function totalCount(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 contributorTotalCount(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) {
|
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;
|
id = contributionId;
|
||||||
ContributionData storage c = contributions[id];
|
ContributionData storage c = contributions[id];
|
||||||
|
@ -22,6 +22,7 @@ module.exports = async function(callback) {
|
|||||||
let blockNumber = await kredits.provider.getBlockNumber();
|
let blockNumber = await kredits.provider.getBlockNumber();
|
||||||
let contributions = await kredits.Contribution.all();
|
let contributions = await kredits.Contribution.all();
|
||||||
|
|
||||||
|
console.log(`Current block number: ${blockNumber}`);
|
||||||
contributions.forEach((c) => {
|
contributions.forEach((c) => {
|
||||||
const confirmed = c.confirmedAtBlock <= blockNumber;
|
const confirmed = c.confirmedAtBlock <= blockNumber;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ module.exports = async function(callback) {
|
|||||||
c.contributorId,
|
c.contributorId,
|
||||||
`${c.description}`,
|
`${c.description}`,
|
||||||
c.amount.toString(),
|
c.amount.toString(),
|
||||||
confirmed,
|
`${confirmed} (${c.confirmedAtBlock})`,
|
||||||
c.vetoed,
|
c.vetoed,
|
||||||
c.claimed,
|
c.claimed,
|
||||||
c.ipfsHash
|
c.ipfsHash
|
||||||
@ -38,6 +39,9 @@ module.exports = async function(callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(table.toString());
|
console.log(table.toString());
|
||||||
|
|
||||||
|
let totalContributionBalances = await kredits.Contribution.functions.totalCount(true);
|
||||||
|
console.log(`Total confirmed balance: ${totalContributionBalances}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user