Compare commits
1 Commits
v3.0.0
...
feature/co
| Author | SHA1 | Date | |
|---|---|---|---|
| 759436f870 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
build
|
||||
node_modules
|
||||
.ganache-db
|
||||
.tm_properties
|
||||
.ganache-db
|
||||
17
README.mdown
17
README.mdown
@@ -81,29 +81,30 @@ At some point these should be moved into a real nice CLI.
|
||||
To run these scripts use `truffle exec`. For example: `truffle exec scripts/add-proposal.js`
|
||||
|
||||
### cli.js
|
||||
|
||||
Call any function on any contract:
|
||||
|
||||
$ truffle exec scripts/cli.js
|
||||
$ truffle exec scripts/cli.js <Contract Name> <Function> [<optional> <arguments>]
|
||||
|
||||
For example:
|
||||
$ truffle exec scripts/cli.js Operator proposalsCount
|
||||
|
||||
### repl.js
|
||||
Similar to cli.js but only provides a REPL with an initialized `kredits` instance.
|
||||
|
||||
$ truffle exec scripts/repl.js
|
||||
Please note that the contract name and the function are case sensitive.
|
||||
|
||||
### add-contributor.js
|
||||
Adds a new core contributor, creates a proposal for the new contributor and votes for that one.
|
||||
|
||||
$ truffle exec scripts/add-contributor.js
|
||||
$ truffle exec scripts/add-contributor.js <ethereum address> [<profile IPFS hash>]
|
||||
|
||||
### add-proposal.js
|
||||
Adds a new proposal for an existing contributor
|
||||
|
||||
$ truffle exec scripts/add-proposal.js
|
||||
$ truffle exec scripts/add-proposal.js <ethereum address> [<proposal IPFS hash>]
|
||||
|
||||
### send-funds.js
|
||||
Sends funds to an address. Helpful in development mode to for example fund a metamask account.
|
||||
|
||||
$ truffle exec scripts/send-funds.js
|
||||
$ truffle exec scripts/send-funds.js <ethereum address>
|
||||
|
||||
### seeds.js
|
||||
Run seeds defined in `config/seeds.js`.
|
||||
|
||||
@@ -6,8 +6,4 @@ let contractCalls = [
|
||||
['Operator', 'addProposal', [{contributorId: 3, amount: 100, kind: 'code', description: 'hacks on kredits', url: '' }, {gasLimit: 350000}]],
|
||||
['Operator', 'vote', ['1', {gasLimit: 250000}]]
|
||||
];
|
||||
let funds = [
|
||||
'0x7e8f313c56f809188313aa274fa67ee58c31515d',
|
||||
'0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827'
|
||||
];
|
||||
module.exports = { contractCalls, funds };
|
||||
module.exports = { contractCalls };
|
||||
|
||||
@@ -110,14 +110,7 @@ contract Operator is Upgradeable {
|
||||
ProposalVoted(proposalId, voterId, p.votesCount);
|
||||
}
|
||||
|
||||
function batchVote(uint256[] _proposalIds) public coreOnly {
|
||||
for (uint256 i = 0; i < _proposalIds.length; i++) {
|
||||
vote(_proposalIds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function executeProposal(uint proposalId) private {
|
||||
|
||||
var p = proposals[proposalId];
|
||||
require(!p.executed);
|
||||
require(p.votesCount >= p.votesNeeded);
|
||||
|
||||
@@ -34,30 +34,6 @@ class Contributor extends Base {
|
||||
});
|
||||
}
|
||||
|
||||
filterByAccount(search) {
|
||||
return this._byAccount(search, 'filter');
|
||||
}
|
||||
|
||||
findByAccount(search) {
|
||||
return this._byAccount(search, 'find');
|
||||
}
|
||||
|
||||
_byAccount(search, method = 'filter') {
|
||||
return this.all().then((contributors) => {
|
||||
const searchEntries = Object.entries(search);
|
||||
|
||||
return contributors[method]((contributor) => {
|
||||
if (!contributor.accounts) { return false; }
|
||||
return contributor.accounts.find((account) => {
|
||||
return searchEntries.every((item) => {
|
||||
let [ key, value ] = item;
|
||||
return account[key] === value;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
add(contributorAttr, callOptions = {}) {
|
||||
let json = ContributorSerializer.serialize(contributorAttr);
|
||||
// TODO: validate against schema
|
||||
|
||||
@@ -63,11 +63,6 @@ class Kredits {
|
||||
return this.contractFor('contributors');
|
||||
}
|
||||
|
||||
get Contributors() {
|
||||
console.log('Contributors is deprecated use Contributor instead');
|
||||
return this.Contributor;
|
||||
}
|
||||
|
||||
get Operator() {
|
||||
return this.contractFor('operator');
|
||||
}
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kredits-contracts",
|
||||
"version": "3.0.0",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kredits-contracts",
|
||||
"version": "3.0.0",
|
||||
"version": "1.0.0",
|
||||
"description": "Ethereum contracts and npm wrapper for Kredits",
|
||||
"main": "./lib/kredits.js",
|
||||
"directories": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
const promptly = require('promptly');
|
||||
const bs58 = require('bs58');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
@@ -36,7 +37,7 @@ module.exports = function(callback) {
|
||||
console.log("\nAdding contributor:");
|
||||
console.log(contributorAttributes);
|
||||
|
||||
kredits.Contributor.add(contributorAttributes, { gasLimit: 250000 }).then((result) => {
|
||||
kredits.Contributor.add(contributorAttributes, {gasLimit: 250000}).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
|
||||
@@ -1,46 +1,38 @@
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
const Operator = artifacts.require('./Operator.sol');
|
||||
const Contributors = artifacts.require('./Contributors.sol');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
const bs58 = require('bs58');
|
||||
|
||||
function getBytes32FromMultiash(multihash) {
|
||||
const decoded = bs58.decode(multihash);
|
||||
|
||||
return {
|
||||
digest: `0x${decoded.slice(2).toString('hex')}`,
|
||||
hashFunction: decoded[0],
|
||||
size: decoded[1],
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function(callback) {
|
||||
Registry.deployed().then(async (registry) => {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
var operatorAddress = await registry.getProxyFor('Operator');
|
||||
var contributorsAddress = await registry.getProxyFor('Contributors');
|
||||
|
||||
console.log(`Using operator at: ${kredits.Operator.contract.address}`);
|
||||
var operator = await Operator.at(operatorAddress);
|
||||
var contributors = await Contributors.at(contributorsAddress);
|
||||
|
||||
let contributor = await promptly.prompt('Contributor (address or id): ');
|
||||
let contributorId;
|
||||
if (contributor.length < 5) {
|
||||
contributorId = contributor;
|
||||
} else {
|
||||
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor);
|
||||
}
|
||||
console.log(`Creating a proposal for contributor ID #${contributorId}`);
|
||||
let recipientAddress = await promptly.prompt('Contributor address: ');
|
||||
let ipfsHash = await promptly.prompt('IPFS hash (blank for default): ', { default: 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs' });
|
||||
|
||||
let contributionAttributes = {
|
||||
contributorId,
|
||||
amount: await promptly.prompt('Amount: '),
|
||||
description: await promptly.prompt('Description: '),
|
||||
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
|
||||
url: await promptly.prompt('URL: ', { default: '' })
|
||||
}
|
||||
let multihash = getBytes32FromMultiash(ipfsHash);
|
||||
|
||||
console.log("\nAdding proposal:");
|
||||
console.log(contributionAttributes);
|
||||
let contributorId = await contributors.getContributorIdByAddress(recipientAddress);
|
||||
|
||||
kredits.Operator.addProposal(contributionAttributes, { gasLimit: 300000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create proposal');
|
||||
console.log(error);
|
||||
});
|
||||
let result = await operator.addProposal(contributorId.toNumber(), 23, multihash.digest, multihash.hashFunction, multihash.size);
|
||||
console.log('Proposal added, tx: ', result.tx);
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,43 +7,30 @@ const Kredits = require('../lib/kredits');
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
let contractName = await promptly.prompt('Contract Name: ');
|
||||
let method = await promptly.prompt('Function: ');
|
||||
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
|
||||
let args = [];
|
||||
if (argumentInput !== '') {
|
||||
args = argumentInput.split(',').map(a => a.trim());
|
||||
}
|
||||
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
|
||||
let contractName = await promptly.prompt('Contract Name: ');
|
||||
const contractWrapper = kredits[contractName];
|
||||
const contract = kredits[contractName].contract;
|
||||
console.log(`Using ${contractName} at ${contract.address}`);
|
||||
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
||||
|
||||
let method;
|
||||
method = await promptly.prompt('Function (? for available functions): ');
|
||||
while (method === '?') {
|
||||
console.log(`Contract functions: ${JSON.stringify(Object.keys(contractWrapper.functions))}`);
|
||||
console.log(`\nWrapper functions: ${JSON.stringify(Object.getOwnPropertyNames(Object.getPrototypeOf(contractWrapper)))}`);
|
||||
console.log("\n");
|
||||
|
||||
method = await promptly.prompt('Function: ');
|
||||
}
|
||||
if (!contractWrapper[method] && !contractWrapper.functions[method]) {
|
||||
if (!contract[method]) {
|
||||
callback(new Error(`Method ${method} is not defined on ${contractName}`));
|
||||
return;
|
||||
}
|
||||
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
|
||||
let args = [];
|
||||
if (argumentInput !== '') {
|
||||
args = argumentInput.split(',').map(a => a.trim());
|
||||
}
|
||||
console.log(`Using ${contractName} at ${contractWrapper.contract.address}`);
|
||||
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
||||
|
||||
let func;
|
||||
if (contractWrapper[method]) {
|
||||
func = contractWrapper[method];
|
||||
} else {
|
||||
func = contractWrapper.functions[method];
|
||||
}
|
||||
func.apply(contractWrapper, args).then((result) => {
|
||||
contract[method](...args).then((result) => {
|
||||
console.log("\nResult:");
|
||||
console.log(result);
|
||||
|
||||
@@ -51,7 +38,7 @@ module.exports = function(callback) {
|
||||
console.log(`defined variables: result, ${contractName}, kredis`);
|
||||
let r = REPL.start();
|
||||
r.context.result = result;
|
||||
r.context[contractName] = contractWrapper;
|
||||
r.context[contractName] = contract;
|
||||
r.context.kredits = kredits;
|
||||
|
||||
r.on('exit', () => {
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
const REPL = require('repl');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
console.log(`defined variables: kredits, web3`);
|
||||
let r = REPL.start();
|
||||
r.context.kredits = kredits;
|
||||
r.context.web3 = web3;
|
||||
|
||||
r.on('exit', () => {
|
||||
console.log('Bye');
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -17,18 +17,6 @@ module.exports = function(callback) {
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
|
||||
let fundingAmount = 2;
|
||||
each(seeds.funds, (address, next) => {
|
||||
console.log(`funding ${address} with 2 ETH`);
|
||||
web3.eth.sendTransaction({
|
||||
to: address,
|
||||
value: web3.toWei(fundingAmount),
|
||||
from: web3.eth.accounts[0]
|
||||
},
|
||||
(result) => { next(); }
|
||||
)
|
||||
});
|
||||
|
||||
each(seeds.contractCalls, (call, next) => {
|
||||
let [contractName, method, args] = call;
|
||||
let contractWrapper = kredits[contractName];
|
||||
|
||||
Reference in New Issue
Block a user