Merge pull request #121 from 67P/refactor/amounts_vs_counts
Improve totalKreditsEarned
This commit is contained in:
commit
17bc4e7d8f
@ -118,22 +118,22 @@ contract Contribution is AragonApp {
|
|||||||
// Custom functions
|
// Custom functions
|
||||||
//
|
//
|
||||||
|
|
||||||
function totalKreditsEarned(bool confirmedOnly) public view returns (uint256 count) {
|
function totalKreditsEarned(bool confirmedOnly) public view returns (uint32 amount) {
|
||||||
for (uint32 i = 1; i <= contributionsCount; i++) {
|
for (uint32 i = 1; i <= contributionsCount; i++) {
|
||||||
ContributionData memory c = contributions[i];
|
ContributionData memory c = contributions[i];
|
||||||
if (block.number >= c.confirmedAtBlock || !confirmedOnly) {
|
if (!c.vetoed && (block.number >= c.confirmedAtBlock || !confirmedOnly)) {
|
||||||
count += c.amount; // should use safemath
|
amount += c.amount; // should use safemath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint256 count) {
|
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint32 amount) {
|
||||||
uint256 tokenBalance = ownedContributions[contributorId].length;
|
uint256 tokenCount = ownedContributions[contributorId].length;
|
||||||
for (uint256 i = 0; i < tokenBalance; i++) {
|
for (uint256 i = 0; i < tokenCount; i++) {
|
||||||
uint32 cId = ownedContributions[contributorId][i];
|
uint32 cId = ownedContributions[contributorId][i];
|
||||||
ContributionData memory c = contributions[cId];
|
ContributionData memory c = contributions[cId];
|
||||||
if (block.number >= c.confirmedAtBlock || !confirmedOnly) {
|
if (!c.vetoed && (block.number >= c.confirmedAtBlock || !confirmedOnly)) {
|
||||||
count += c.amount; // should use safemath
|
amount += c.amount; // should use safemath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ interface ITokenBalance {
|
|||||||
function balanceOf(address contributorAccount) public view returns (uint256);
|
function balanceOf(address contributorAccount) public view returns (uint256);
|
||||||
}
|
}
|
||||||
interface IContributionBalance {
|
interface IContributionBalance {
|
||||||
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint256 count);
|
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint32 amount);
|
||||||
function balanceOf(address owner) public view returns (uint256);
|
function balanceOf(address owner) public view returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ contract Contributor is AragonApp {
|
|||||||
return contributors[id];
|
return contributors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ) {
|
function getContributorById(uint32 _id) public view returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, uint32 totalKreditsEarned, uint256 contributionsCount, bool exists ) {
|
||||||
id = _id;
|
id = _id;
|
||||||
Contributor storage c = contributors[_id];
|
Contributor storage c = contributors[_id];
|
||||||
account = c.account;
|
account = c.account;
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user