Hello wrapper library
This commit is contained in:
parent
38a25caaa4
commit
d5e68e1639
@ -1 +1 @@
|
|||||||
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributors","outputs":[{"name":"account","type":"address"},{"name":"profileHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"contributorIds","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldProfileHash","type":"bytes32"},{"indexed":false,"name":"newProfileHash","type":"bytes32"}],"name":"ContributorProfileUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldAddress","type":"address"},{"indexed":false,"name":"newAddress","type":"address"}],"name":"ContributorAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"_address","type":"address"}],"name":"ContributorAdded","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_id","type":"uint256"},{"name":"_oldAddress","type":"address"},{"name":"_newAddress","type":"address"}],"name":"updateContributorAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_id","type":"uint256"},{"name":"_hashFunction","type":"uint8"},{"name":"_hashSize","type":"uint8"},{"name":"_profileHash","type":"bytes32"}],"name":"updateContributorProfileHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"},{"name":"_hashFunction","type":"uint8"},{"name":"_hashSize","type":"uint8"},{"name":"_profileHash","type":"bytes32"},{"name":"isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"isCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"addressIsCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"addressExists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributorById","outputs":[{"name":"account","type":"address"},{"name":"profileHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"},{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]
|
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributors","outputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"contributorIds","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldIpfsHash","type":"bytes32"},{"indexed":false,"name":"newIpfsHash","type":"bytes32"}],"name":"ContributorProfileUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldAccount","type":"address"},{"indexed":false,"name":"newAccount","type":"address"}],"name":"ContributorAccountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"account","type":"address"}],"name":"ContributorAdded","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"oldAccount","type":"address"},{"name":"newAccount","type":"address"}],"name":"updateContributorAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"updateContributorIpfsHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"isCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressIsCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressExists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributorById","outputs":[{"name":"id","type":"uint256"},{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"balance","type":"uint256"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}]
|
@ -1 +1 @@
|
|||||||
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"creator","type":"address"},{"name":"recipientId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"creator","type":"address"},{"indexed":false,"name":"recipient","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"voter","type":"address"},{"indexed":false,"name":"totalVotes","type":"uint256"}],"name":"ProposalVoted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"recipient","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalExecuted","type":"event"},{"constant":true,"inputs":[],"name":"contributorsContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"},{"name":"_profileHash","type":"bytes32"},{"name":"_hashFunction","type":"uint8"},{"name":"_hashSize","type":"uint8"},{"name":"_isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_id","type":"uint256"},{"name":"_profileHash","type":"bytes32"},{"name":"_hashFunction","type":"uint8"},{"name":"_hashSize","type":"uint8"}],"name":"updateContributorProfileHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributor","outputs":[{"name":"account","type":"address"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"profileHash","type":"bytes32"},{"name":"isCore","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"uint256"},{"name":"_amount","type":"uint256"},{"name":"_ipfsHash","type":"bytes32"},{"name":"_hashFunction","type":"uint8"},{"name":"_hashSize","type":"uint8"}],"name":"addProposal","outputs":[{"name":"proposalId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_proposalId","type":"uint256"}],"name":"vote","outputs":[{"name":"_pId","type":"uint256"},{"name":"_executed","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sender","type":"address"},{"name":"_proposalId","type":"uint256"}],"name":"hasVotedFor","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}]
|
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"creatorAccount","type":"address"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"voterId","type":"uint256"},{"indexed":false,"name":"totalVotes","type":"uint256"}],"name":"ProposalVoted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalExecuted","type":"event"},{"constant":true,"inputs":[],"name":"contributorsContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"addProposal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"getProposal","outputs":[{"name":"id","type":"uint256"},{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"voterIds","type":"uint256[]"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
|
@ -1 +1 @@
|
|||||||
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"proposalId","type":"uint256"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_proposalId","type":"uint256"}],"name":"mintFor","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
|
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"proposalId","type":"uint256"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"contributorAccount","type":"address"},{"name":"amount","type":"uint256"},{"name":"proposalId","type":"uint256"}],"name":"mintFor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
|
@ -1 +1 @@
|
|||||||
{"100":"0x34262a9471ede40e94497d110652dcf0f26fa0db"}
|
{"100":"0xa7fc9b1f678c41396b53904f94f50a42ff44d826"}
|
@ -1 +1 @@
|
|||||||
{"100":"0x901f3e99a170619857b354c101aa97244885a39e"}
|
{"100":"0x95d3bd7d136bb0b7ac9988097e964236f8a9976e"}
|
@ -1 +1 @@
|
|||||||
{"100":"0x9447a29373cf3ce0edf41804820c2a9da0ef4fd9"}
|
{"100":"0x513f8e80a8fbb9fa188320ecf231efcf2f6da9c5"}
|
@ -1 +1 @@
|
|||||||
{"100":"0x8ecf9fa8a1c50179cef966d53aaee3d2a382c932"}
|
{"100":"0x3fc29fbe40c2d0ca78c7e81342f00226650fe2ad"}
|
27
lib/contracts/base.js
Normal file
27
lib/contracts/base.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class Base {
|
||||||
|
constructor(contract) {
|
||||||
|
this.contract = contract;
|
||||||
|
}
|
||||||
|
|
||||||
|
get functions() {
|
||||||
|
return this.contract.functions;
|
||||||
|
}
|
||||||
|
|
||||||
|
get ipfs() {
|
||||||
|
if (!this._ipfsAPI) { throw new Error('IPFS API not configured; please set an ipfs instance'); }
|
||||||
|
return this._ipfsAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
set ipfs(ipfsAPI) {
|
||||||
|
this._ipfsAPI = ipfsAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
on(type, callback) {
|
||||||
|
let eventMethod = `on${type.toLowerCase()}`;
|
||||||
|
// Don't use this.contract.events here. Seems to be a bug in ethers.js
|
||||||
|
this.contract[eventMethod] = callback;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = Base;
|
58
lib/contracts/contributor.js
Normal file
58
lib/contracts/contributor.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
const ethers = require('ethers');
|
||||||
|
const RSVP = require('rsvp');
|
||||||
|
|
||||||
|
const ContributorSerializer = require('../serializers/contributor');
|
||||||
|
const Base = require('./base');
|
||||||
|
|
||||||
|
class Contributor extends Base {
|
||||||
|
all() {
|
||||||
|
return this.functions.contributorsCount()
|
||||||
|
.then((count) => {
|
||||||
|
count = count.toNumber();
|
||||||
|
let contributors = [];
|
||||||
|
|
||||||
|
for (let id = 1; id <= count; id++) {
|
||||||
|
contributors.push(this.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return RSVP.all(contributors);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getById(id) {
|
||||||
|
id = ethers.utils.bigNumberify(id);
|
||||||
|
|
||||||
|
return this.functions.getContributorById(id)
|
||||||
|
.then((data) => {
|
||||||
|
// TODO: remove when naming updated on the contract
|
||||||
|
data.hashDigest = data.ipfsHash;
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
// Fetch IPFS data if available
|
||||||
|
.then((data) => {
|
||||||
|
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
add(contributorAttr) {
|
||||||
|
let json = ContributorSerializer.serialize(contributorAttr);
|
||||||
|
// TODO: validate against schema
|
||||||
|
|
||||||
|
return this.ipfs
|
||||||
|
.add(json)
|
||||||
|
.then((ipfsHashAttr) => {
|
||||||
|
let contributor = [
|
||||||
|
contributorAttr.address,
|
||||||
|
ipfsHashAttr.hashDigest,
|
||||||
|
ipfsHashAttr.hashFunction,
|
||||||
|
ipfsHashAttr.hashSize,
|
||||||
|
contributorAttr.isCore,
|
||||||
|
];
|
||||||
|
|
||||||
|
console.log('[kredits] addContributor', ...contributor);
|
||||||
|
return this.functions.addContributor(...contributor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Contributor;
|
5
lib/contracts/index.js
Normal file
5
lib/contracts/index.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
Contributors: require('./contributor'),
|
||||||
|
Operator: require('./operator'),
|
||||||
|
Token: require('./token')
|
||||||
|
}
|
58
lib/contracts/operator.js
Normal file
58
lib/contracts/operator.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
const ethers = require('ethers');
|
||||||
|
const RSVP = require('rsvp');
|
||||||
|
|
||||||
|
const ContributionSerializer = require('../serializers/contribution');
|
||||||
|
const Base = require('./base');
|
||||||
|
|
||||||
|
class Operator extends Base {
|
||||||
|
all() {
|
||||||
|
return this.functions.proposalsCount()
|
||||||
|
.then((count) => {
|
||||||
|
count = count.toNumber();
|
||||||
|
let proposals = [];
|
||||||
|
|
||||||
|
for (let id = 1; id <= count; id++) {
|
||||||
|
proposals.push(this.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return RSVP.all(proposals);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getById(id) {
|
||||||
|
id = ethers.utils.bigNumberify(id);
|
||||||
|
|
||||||
|
return this.functions.getProposal(id)
|
||||||
|
.then((data) => {
|
||||||
|
// TODO: remove when naming updated on the contract
|
||||||
|
data.hashDigest = data.ipfsHash;
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
// Fetch IPFS data if available
|
||||||
|
.then((data) => {
|
||||||
|
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addProposal(proposalAttr) {
|
||||||
|
let json = ContributionSerializer.serialize(proposalAttr);
|
||||||
|
// TODO: validate against schema
|
||||||
|
|
||||||
|
return this.ipfs
|
||||||
|
.add(json)
|
||||||
|
.then((ipfsHashAttr) => {
|
||||||
|
let proposal = [
|
||||||
|
proposalAttr.contributorId,
|
||||||
|
proposalAttr.amount,
|
||||||
|
ipfsHashAttr.hashDigest,
|
||||||
|
ipfsHashAttr.hashFunction,
|
||||||
|
ipfsHashAttr.hashSize,
|
||||||
|
];
|
||||||
|
|
||||||
|
console.log('[kredits] addProposal', ...proposal);
|
||||||
|
return this.functions.addProposal(...proposal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Operator;
|
7
lib/contracts/token.js
Normal file
7
lib/contracts/token.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const Base = require('./base');
|
||||||
|
|
||||||
|
class Token extends Base {
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Base;
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
module.exports = ["Contributors","Operator","Registry","Token"];
|
|
128
lib/kredits.js
Normal file
128
lib/kredits.js
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
const ethers = require('ethers');
|
||||||
|
const RSVP = require('rsvp');
|
||||||
|
|
||||||
|
const abis = {
|
||||||
|
Contributors: require('./abis/Contributors.json'),
|
||||||
|
Operator: require('./abis/Operator.json'),
|
||||||
|
Registry: require('./abis/Registry.json'),
|
||||||
|
Token: require('./abis/Token.json')
|
||||||
|
};
|
||||||
|
const addresses = {
|
||||||
|
Registry: require('./addresses/Registry.json')
|
||||||
|
};
|
||||||
|
|
||||||
|
const contracts = require('./contracts');
|
||||||
|
const IPFS = require('./utils/ipfs')
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
function capitalize(word) {
|
||||||
|
let [first, ...rest] = word;
|
||||||
|
return `${first.toUpperCase()}${rest.join('')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Kredits {
|
||||||
|
static get contractNames() {
|
||||||
|
return Object.keys(abis);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(provider, signer, addresses) {
|
||||||
|
this.provider = provider;
|
||||||
|
this.signer = signer;
|
||||||
|
|
||||||
|
// Initialize our registry contract
|
||||||
|
this.addresses = addresses;
|
||||||
|
this.contracts = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static setup(provider, signer, ipfsConfig) {
|
||||||
|
this.ipfsConfig = ipfsConfig;
|
||||||
|
let ipfsAPI = new IPFS(ipfsConfig);
|
||||||
|
this.ipfs = ipfsAPI;
|
||||||
|
|
||||||
|
return this.ipfs._ipfsAPI.id().catch((error) => {
|
||||||
|
throw new Error(`IPFS node not available; config: ${JSON.stringify(ipfsConfig)} - ${error.message}`);
|
||||||
|
}).then(() => {
|
||||||
|
|
||||||
|
let registryContract = this.initRegistryContract(provider);
|
||||||
|
|
||||||
|
let addresses = Kredits.contractNames.reduce((mem, name) => {
|
||||||
|
let contractName = capitalize(name);
|
||||||
|
mem[contractName] = registryContract.functions.getProxyFor(contractName).catch((error) => {
|
||||||
|
throw new Error(`Failed to get address for ${contractName} from registry at ${registryContract.address}
|
||||||
|
- correct registry? does it have version entry? - ${error.message}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return mem;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return RSVP.hash(addresses)
|
||||||
|
.then((addresses) => {
|
||||||
|
let kredits = new Kredits(provider, signer, addresses);
|
||||||
|
kredits.ipfs = ipfsAPI;
|
||||||
|
return kredits;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static initRegistryContract(provider) {
|
||||||
|
let address = addresses['Registry'][provider.chainId];
|
||||||
|
if (!address) {
|
||||||
|
throw new Error(`Registry address not found; invalid network?
|
||||||
|
requested network: ${provider.chainId}
|
||||||
|
supported networks: ${Object.keys(addresses['Registry'])}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
provider.getCode(address).then((code) => {
|
||||||
|
// not sure if we always get the same return value of the code is not available
|
||||||
|
// that's why checking if it is < 5 long
|
||||||
|
if (code === '0x00' || code.length < 5) {
|
||||||
|
throw new Error(`Registry not found at ${address} on network ${provider.chainId}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let abi = abis['Registry'];
|
||||||
|
console.log('Initialize registry contract:', address, abi, provider);
|
||||||
|
return new ethers.Contract(address, abi, provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
get ipfs() {
|
||||||
|
return this._ipfsAPI;
|
||||||
|
}
|
||||||
|
set ipfs(ipfs) {
|
||||||
|
this._ipfsAPI = ipfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
get Contributor() {
|
||||||
|
// TODO: rename to contributor
|
||||||
|
return this.contractFor('contributors');
|
||||||
|
}
|
||||||
|
|
||||||
|
get Operator() {
|
||||||
|
return this.contractFor('operator');
|
||||||
|
}
|
||||||
|
|
||||||
|
get Token() {
|
||||||
|
return this.contractFor('token');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should be private
|
||||||
|
contractFor(name) {
|
||||||
|
if (this.contracts[name]) {
|
||||||
|
return this.contracts[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
let contractName = capitalize(name);
|
||||||
|
console.log(contractName);
|
||||||
|
console.log(contracts);
|
||||||
|
let address = this.addresses[contractName];
|
||||||
|
if (!address || !abis[contractName]) {
|
||||||
|
throw new Error(`Address or ABI not found for ${contractName}`);
|
||||||
|
}
|
||||||
|
let contract = new ethers.Contract(address, abis[contractName], this.signer);
|
||||||
|
this.contracts[name] = new contracts[contractName](contract);
|
||||||
|
this.contracts[name].ipfs = this.ipfs;
|
||||||
|
|
||||||
|
return this.contracts[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Kredits;
|
66
lib/serializers/contribution.js
Normal file
66
lib/serializers/contribution.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* Handle serialization for JSON-LD object of the contribution, according to
|
||||||
|
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contribution.json
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
class Contribution {
|
||||||
|
/**
|
||||||
|
* Deserialize JSON to object
|
||||||
|
*
|
||||||
|
* @method
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
static deserialize(serialized) {
|
||||||
|
let {
|
||||||
|
kind,
|
||||||
|
description,
|
||||||
|
details,
|
||||||
|
url,
|
||||||
|
} = JSON.parse(serialized.toString('utf8'));
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind,
|
||||||
|
description,
|
||||||
|
details,
|
||||||
|
url,
|
||||||
|
ipfsData: serialized,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize object to JSON
|
||||||
|
*
|
||||||
|
* @method
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
static serialize(deserialized) {
|
||||||
|
let {
|
||||||
|
contributorIpfsHash,
|
||||||
|
kind,
|
||||||
|
description,
|
||||||
|
url,
|
||||||
|
} = deserialized;
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"@context": "https://schema.kosmos.org",
|
||||||
|
"@type": "Contribution",
|
||||||
|
"contributor": {
|
||||||
|
"ipfs": contributorIpfsHash
|
||||||
|
},
|
||||||
|
kind,
|
||||||
|
description,
|
||||||
|
"details": {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
data["url"] = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write it pretty to ipfs
|
||||||
|
return JSON.stringify(data, null, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Contribution;
|
95
lib/serializers/contributor.js
Normal file
95
lib/serializers/contributor.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/**
|
||||||
|
* Handle serialization for JSON-LD object of the contributor, according to
|
||||||
|
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contributor.json
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @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,
|
||||||
|
github_uid,
|
||||||
|
github_username,
|
||||||
|
wiki_username,
|
||||||
|
ipfsData: serialized,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize object to JSON
|
||||||
|
*
|
||||||
|
* @method
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
static serialize(deserialized) {
|
||||||
|
let {
|
||||||
|
name,
|
||||||
|
kind,
|
||||||
|
url,
|
||||||
|
github_uid,
|
||||||
|
github_username,
|
||||||
|
wiki_username,
|
||||||
|
} = deserialized;
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"@context": "https://schema.kosmos.org",
|
||||||
|
"@type": "Contributor",
|
||||||
|
kind,
|
||||||
|
name,
|
||||||
|
"accounts": []
|
||||||
|
};
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
data["url"] = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (github_uid) {
|
||||||
|
data.accounts.push({
|
||||||
|
"site": "github.com",
|
||||||
|
"uid": github_uid,
|
||||||
|
"username": github_username,
|
||||||
|
"url": `https://github.com/${github_username}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wiki_username) {
|
||||||
|
data.accounts.push({
|
||||||
|
"site": "wiki.kosmos.org",
|
||||||
|
"username": wiki_username,
|
||||||
|
"url": `https://wiki.kosmos.org/User:${wiki_username}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write it pretty to ipfs
|
||||||
|
return JSON.stringify(data, null, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Contributor;
|
59
lib/utils/ipfs.js
Normal file
59
lib/utils/ipfs.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
const ipfsAPI = require('ipfs-api');
|
||||||
|
const multihashes = require('multihashes');
|
||||||
|
|
||||||
|
class IPFS {
|
||||||
|
|
||||||
|
constructor(config) {
|
||||||
|
this._ipfsAPI = ipfsAPI(config);
|
||||||
|
this._config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
catAndMerge(data, deserialize) {
|
||||||
|
// if no hash details are found simply return the data; nothing to merge
|
||||||
|
if (!data.hashSize || data.hashSize === 0) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// merge ipfsHash (encoded from hashDigest, hashSize, hashFunction)
|
||||||
|
data.ipfsHash = this.encodeHash(data);
|
||||||
|
|
||||||
|
return this.cat(data)
|
||||||
|
.then(deserialize)
|
||||||
|
.then((attributes) => {
|
||||||
|
return Object.assign({}, data, attributes);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
add(data) {
|
||||||
|
return this._ipfsAPI
|
||||||
|
.add(new this._ipfsAPI.Buffer(data))
|
||||||
|
.then((res) => {
|
||||||
|
return this.decodeHash(res[0].hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
cat(hashData) {
|
||||||
|
let ipfsHash = hashData; // default - if it is a string
|
||||||
|
if (hashData.hasOwnProperty('hashSize')) {
|
||||||
|
ipfsHash = this.encodeHash(hashData);
|
||||||
|
}
|
||||||
|
return this._ipfsAPI.cat(ipfsHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
decodeHash(ipfsHash) {
|
||||||
|
let multihash = multihashes.decode(multihashes.fromB58String(ipfsHash));
|
||||||
|
return {
|
||||||
|
hashDigest: '0x' + multihashes.toHexString(multihash.digest),
|
||||||
|
hashSize: multihash.length,
|
||||||
|
hashFunction: multihash.code,
|
||||||
|
ipfsHash: ipfsHash
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
encodeHash(hashData) {
|
||||||
|
let digest = this._ipfsAPI.Buffer.from(hashData.hashDigest.slice(2), 'hex');
|
||||||
|
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = IPFS;
|
408
package-lock.json
generated
408
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
"name": "kredits-contracts",
|
"name": "kredits-contracts",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Ethereum contracts and npm wrapper for Kredits",
|
"description": "Ethereum contracts and npm wrapper for Kredits",
|
||||||
"main": "index.js",
|
"main": "./lib/kredits.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
@ -25,8 +25,12 @@
|
|||||||
"homepage": "https://github.com/67P/truffle-kredits#readme",
|
"homepage": "https://github.com/67P/truffle-kredits#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ganache-cli": "^6.0.3",
|
"ganache-cli": "^6.0.3",
|
||||||
"ipfs-api": "^19.0.0",
|
|
||||||
"truffle": "^4.1.3",
|
"truffle": "^4.1.3",
|
||||||
"zeppelin-solidity": "^1.7.0"
|
"zeppelin-solidity": "^1.7.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ethers": "^3.0.15",
|
||||||
|
"ipfs-api": "^19.0.0",
|
||||||
|
"rsvp": "^4.8.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,6 @@ files.forEach((fileName) => {
|
|||||||
}, {});
|
}, {});
|
||||||
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
||||||
|
|
||||||
let indexFile = path.join(libPath, 'index.js');
|
|
||||||
fs.writeFileSync(indexFile, `module.exports = ${JSON.stringify(files)};`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("Don't forget to reaload the JSON files from your application; i.e. restart kredits-web");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user