diff --git a/README.mdown b/README.mdown index 4f68baa..ce60c37 100644 --- a/README.mdown +++ b/README.mdown @@ -56,6 +56,40 @@ Truffle keeps track of already executed migration scripts. To reset the migratio Migration scripts can also be run from within `truffle console` or `truffle develop` +To initially bootstrap a local development chain in ganache you can use the bootstrap script: + + $ npm run bootstrap (= `truffle migrate --reset && truffle exec scripts/seeds.js && npm run build-json`) + + +## Helper scripts + +`scripts/` contains some helper scripts to interact with the contracts from the CLI. +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` + +### 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 [] + +### add-proposal.js +Adds a new proposal for an existing contributor + + $ truffle exec scripts/add-proposal.js [] + +### 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 + +### seeds.js +Run seeds defined in `config/seeds.js`. + + $ truffle exec scripts/seeds.js + or + $ npm run seeds + ## Upgradeable contracts diff --git a/scripts/add-contributor.js b/scripts/add-contributor.js index a930477..1ea00ee 100644 --- a/scripts/add-contributor.js +++ b/scripts/add-contributor.js @@ -30,19 +30,18 @@ module.exports = function(callback) { let ipfsHash = process.argv[5] || 'QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj'; let contributorMultihash = getBytes32FromMultiash(ipfsHash); let isCore = true; - operator.addContributor(contributorToAddAddress, contributorMultihash.digest, contributorMultihash.hashFunction, contributorMultihash.size, isCore).then((result) => { - console.log('Contributor added, tx: ', result.tx); - }); + let contributorResult = await operator.addContributor(contributorToAddAddress, contributorMultihash.digest, contributorMultihash.hashFunction, contributorMultihash.size, isCore); + console.log('Contributor added, tx: ', contributorResult.tx); - var contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress); + let contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress); let proposalMultihash = getBytes32FromMultiash('QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs'); - operator.addProposal(contributorId, 23, proposalMultihash.digest, proposalMultihash.hashFunction, proposalMultihash.size).then((result) => { - console.log('Proposal added, tx: ', result.tx); - }); + let proposalResult = await operator.addProposal(contributorId, 23, proposalMultihash.digest, proposalMultihash.hashFunction, proposalMultihash.size); + console.log('Proposal added, tx: ', proposalResult.tx); - var proposalId = await operator.proposalsCount(); - operator.vote(proposalId.toNumber()-1).then((result) => { - console.log('Voted for proposal', proposalId, result.tx); - }) + let proposalId = await operator.proposalsCount(); + let votingResult = operator.vote(proposalId.toNumber()-1); + console.log('Voted for proposal', proposalId.toString(), votingResult.tx); + + callback(); }); } diff --git a/scripts/add-proposal.js b/scripts/add-proposal.js index 49f5f13..35a8c55 100644 --- a/scripts/add-proposal.js +++ b/scripts/add-proposal.js @@ -32,9 +32,9 @@ module.exports = function(callback) { let contributorId = await contributors.getContributorIdByAddress(recipientAddress); - operator.addProposal(contributorId.toNumber(), 23, multihash.digest, multihash.hashFunction, multihash.size).then((result) => { - console.log('Proposal added, tx: ', result.tx); - }); + let result = await operator.addProposal(contributorId.toNumber(), 23, multihash.digest, multihash.hashFunction, multihash.size); + console.log('Proposal added, tx: ', result.tx); + callback(); }); } diff --git a/scripts/seeds.js b/scripts/seeds.js index 773519f..69d79fa 100644 --- a/scripts/seeds.js +++ b/scripts/seeds.js @@ -29,4 +29,6 @@ module.exports = function(callback) { seeds.ipfsContent.forEach((content) => { ipfs.add(new ipfs.Buffer(JSON.stringify(content))).then((result) => { console.log(`[IPFS] added ${result[0].hash}`) }); }); + + callback(); } diff --git a/scripts/send-funds.js b/scripts/send-funds.js index e32287a..262e286 100644 --- a/scripts/send-funds.js +++ b/scripts/send-funds.js @@ -1,5 +1,5 @@ -module.exports = function(cb) { +module.exports = function(callback) { let recipient = process.argv[4]; if (!recipient) { console.log('Please provide a recipient address'); @@ -8,4 +8,6 @@ module.exports = function(cb) { let amount = parseInt(process.argv[5]) || 1; console.log(recipient); web3.eth.sendTransaction({to: recipient, value: web3.toWei(amount), from: web3.eth.accounts[0]}, console.log); + + callback(); }