From 4f5ae01c5a4d711dbf4daa0aba893dcc89a29fe4 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Thu, 28 Mar 2019 11:16:20 +0100 Subject: [PATCH] Add helper funtion to list contract entries --- README.md | 19 ++++++------------ scripts/list-contributions.js | 37 +++++++++++++++++++++++++++++++++++ scripts/list-contributors.js | 36 ++++++++++++++++++++++++++++++++++ scripts/list-proposals.js | 37 +++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 scripts/list-contributions.js create mode 100644 scripts/list-contributors.js create mode 100644 scripts/list-proposals.js diff --git a/README.md b/README.md index 8b5fd8c..bdf4ac4 100644 --- a/README.md +++ b/README.md @@ -100,24 +100,17 @@ instance. $ truffle exec scripts/repl.js -### add-contributor.js +### add-{contributor, contribution, proposal}.js -Adds a new core contributor, creates a proposal for the new contributor and -votes for that one. +Script to add a new entries to the contracts using the JS wrapper - $ truffle exec scripts/add-contributor.js + $ truffle exec scripts/add-{contributor, contribution, proposal}.js -### add-proposal.js +### list-{contributor, contribution, proposal}.js -Adds a new proposal for an existing contributor +List contract entries - $ truffle exec scripts/add-proposal.js - -### add-contribution.js - -Adds a new contribution for an existing contributor - - $ truffle exec scripts/add-contribution.js + $ truffle exec scripts/list-{contributor, contribution, proposal}.js ### send-funds.js diff --git a/scripts/list-contributions.js b/scripts/list-contributions.js new file mode 100644 index 0000000..9b7acb3 --- /dev/null +++ b/scripts/list-contributions.js @@ -0,0 +1,37 @@ +const promptly = require('promptly'); +const Table = require('cli-table'); + +const ethers = require('ethers'); +const Kredits = require('../lib/kredits'); + +const getNetworkId = require('./helpers/networkid.js') + +module.exports = async function(callback) { + const networkId = await getNetworkId(web3) + const provider = new ethers.providers.Web3Provider( + web3.currentProvider, { chainId: parseInt(networkId) } + ); + const kredits = await new Kredits(provider, provider.getSigner()).init(); + + console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`); + + + const table = new Table({ + head: ['ID', 'Contributor account', 'Amount', 'Claimed?', 'Vetoed?', 'Description'] + }) + + let contributions = await kredits.Contribution.all() + + contributions.forEach((c) => { + table.push([ + c.id.toString(), + c.contributor, + c.amount.toString(), + c.claimed, + c.vetoed, + `${c.description}` + ]) + }) + console.log(table.toString()) + callback() +} diff --git a/scripts/list-contributors.js b/scripts/list-contributors.js new file mode 100644 index 0000000..27b3a4f --- /dev/null +++ b/scripts/list-contributors.js @@ -0,0 +1,36 @@ +const promptly = require('promptly'); +const Table = require('cli-table'); + +const ethers = require('ethers'); +const Kredits = require('../lib/kredits'); + +const getNetworkId = require('./helpers/networkid.js') + +module.exports = async function(callback) { + const networkId = await getNetworkId(web3) + const provider = new ethers.providers.Web3Provider( + web3.currentProvider, { chainId: parseInt(networkId) } + ); + const kredits = await new Kredits(provider, provider.getSigner()).init(); + + console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`); + + + const table = new Table({ + head: ['ID', 'Account', 'Core?', 'Name'] + }) + + let contributors = await kredits.Contributor.all() + + contributors.forEach((c) => { + table.push([ + c.id.toString(), + c.account, + c.isCore, + `${c.name}` + ]) + }) + console.log(table.toString()) + callback() +} + diff --git a/scripts/list-proposals.js b/scripts/list-proposals.js new file mode 100644 index 0000000..2b04115 --- /dev/null +++ b/scripts/list-proposals.js @@ -0,0 +1,37 @@ +const promptly = require('promptly'); +const Table = require('cli-table'); + +const ethers = require('ethers'); +const Kredits = require('../lib/kredits'); + +const getNetworkId = require('./helpers/networkid.js') + +module.exports = async function(callback) { + const networkId = await getNetworkId(web3) + const provider = new ethers.providers.Web3Provider( + web3.currentProvider, { chainId: parseInt(networkId) } + ); + const kredits = await new Kredits(provider, provider.getSigner()).init(); + + console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`); + + + const table = new Table({ + head: ['ID', 'Contributor ID', 'Amount', 'Votes', 'Executed?', 'Description'] + }) + + let proposals = await kredits.Proposal.all() + + proposals.forEach((p) => { + table.push([ + p.id.toString(), + p.contributorId.toString(), + p.amount.toString(), + `${p.votesCount.toString()}/${p.votesNeeded.toString()}`, + p.executed, + `${p.description}` + ]) + }) + console.log(table.toString()) + callback() +}