Improve totalKreditsEarned
* Use a more reasonable size of integer * Use better variable names (count != amount, balance != count)
This commit is contained in:
parent
3568d3c141
commit
555cb53c78
@ -127,13 +127,13 @@ contract Contribution is AragonApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user