Add kredits-formatter and additionally format balance #108

Merged
bumi merged 5 commits from feature/kredits-formatter into master 2019-04-24 13:20:45 +00:00
9 changed files with 141 additions and 49 deletions
Showing only changes of commit 48c8f6b9b3 - Show all commits

View File

@ -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];

View File

@ -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

View File

@ -39,12 +39,16 @@ class Contributor extends Record {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
});
}
add(contributorAttr, callOptions = {}) {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
let json = ContributorSerializer.serialize(contributorAttr);
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
// TODO: validate against schema
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
async add(contributorAttr, callOptions = {}) {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
let contributor = new ContributorSerializer(contributorAttr);
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
try { await contributor.validate(); }
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
catch (error) { return Promise.reject(error); }
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
const jsonStr = contributor.serialize();
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
return this.ipfs
.add(json)
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
.add(jsonStr)
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
.then((ipfsHashAttr) => {
let contributor = [
contributorAttr.account,
@ -56,6 +60,30 @@ class Contributor extends Record {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
return this.functions.addContributor(...contributor, callOptions);
});
}
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
updateProfile(contributorId, updateAttr, callOptions = {}) {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
return this.getById(contributorId).then(async (contributor) => {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
let updatedContributorAttr = Object.assign(contributor, updateAttr)
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
let updatedContributor = new ContributorSerializer(updatedContributorAttr);
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
try { await updatedContributor.validate(); }
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
catch (error) { return Promise.reject(error); }
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
const jsonStr = updatedContributor.serialize();
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
return this.ipfs
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
.add(jsonStr)
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
.then(ipfsHashAttr => {
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
return this.functions.updateContributorProfileHash(
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
contributorId,
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
ipfsHashAttr.hashDigest,
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
ipfsHashAttr.hashFunction,
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
ipfsHashAttr.hashSize,
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
callOptions
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
);
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
});
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
});
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
}
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
}
module.exports = Contributor;

raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
raucao commented 2019-04-19 10:04:15 +00:00 (Migrated from github.com)
Review

As this is not a class, but just one formatting function, I'd call the file format_kredits and import it as formatKredits().

As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`
fsmanuel commented 2019-04-19 10:18:25 +00:00 (Migrated from github.com)
Review

I think the convention is a dash for filenames in JS.
👍 formatKredits()

I think the convention is a dash for filenames in JS. 👍 `formatKredits()`

View File

@ -1,3 +1,5 @@
const schemas = require('kosmos-schemas');
const validator = require('../utils/validator');
/**
* Handle serialization for JSON-LD object of the contributor, according to
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contributor.json
@ -6,41 +8,9 @@
* @public
*/
class Contributor {
/**
* Deserialize JSON to object
*
* @method
* @public
*/
static deserialize(serialized) {
let {
name,
kind,
url,
accounts,
} = JSON.parse(serialized.toString('utf8'));
let github_username, github_uid, wiki_username;
let github = accounts.find((a) => a.site === 'github.com');
let wiki = accounts.find((a) => a.site === 'wiki.kosmos.org');
if (github) {
(({ username: github_username, uid: github_uid} = github));
}
if (wiki) {
(({ username: wiki_username } = wiki));
}
return {
name,
kind,
url,
accounts,
github_uid,
github_username,
wiki_username,
ipfsData: serialized,
};
constructor(attrs) {
Object.keys(attrs).forEach(a => this[a] = attrs[a]);
}
/**
@ -49,7 +19,7 @@ class Contributor {
* @method
* @public
*/
static serialize(deserialized) {
serialize () {
let {
name,
kind,
@ -57,7 +27,7 @@ class Contributor {
github_uid,
github_username,
wiki_username,
} = deserialized;
} = this;
let data = {
"@context": "https://schema.kosmos.org",
@ -91,6 +61,55 @@ class Contributor {
// Write it pretty to ipfs
return JSON.stringify(data, null, 2);
}
/**
* Validate serialized data against schema
*
* @public
*/
validate () {
const serialized = JSON.parse(this.serialize());
const valid = validator.validate(serialized, schemas['contributor']);
return valid ? Promise.resolve() : Promise.reject(validator.error);
}
/**
* Deserialize JSON to object
*
* @method
* @public
*/
static deserialize (serialized) {
let {
name,
kind,
url,
accounts,
} = JSON.parse(serialized.toString('utf8'));
let github_username, github_uid, wiki_username;
let github = accounts.find((a) => a.site === 'github.com');
let wiki = accounts.find((a) => a.site === 'wiki.kosmos.org');
if (github) {
(({ username: github_username, uid: github_uid} = github));
}
if (wiki) {
(({ username: wiki_username } = wiki));
}
return {
name,
kind,
url,
accounts,
github_uid,
github_username,
wiki_username,
ipfsData: serialized,
};
}
}
module.exports = Contributor;

View File

@ -26,7 +26,7 @@ module.exports = async function(callback) {
kind: await prompt('Kind (default person): ', {default: 'person'}),
url: await prompt('URL: '),
github_username: await prompt('GitHub username: '),
github_uid: await prompt('GitHub UID: '),
github_uid: parseInt(await prompt('GitHub UID: ')),
wiki_username: await prompt('Wiki username: '),
};

View File

@ -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);
}

View File

@ -15,12 +15,16 @@ module.exports = async function(callback) {
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
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()
try {
const contributors = await kredits.Contributor.all()
} catch(e) {
callback(e);
return;
}
contributors.forEach((c) => {
table.push([
@ -28,11 +32,15 @@ module.exports = async function(callback) {
c.account,
`${c.name}`,
c.isCore,
c.balanceInt,
c.balanceInt.toString(),
c.totalKreditsEarned.toString(),
c.contributionsCount.toString(),
c.ipfsHash
])
})
console.log(table.toString())
callback()
}