Document helper scripts to interact with the contracts

This commit is contained in:
bumi 2018-04-04 21:56:54 +02:00
parent bdd99d58cf
commit 7d52161014
5 changed files with 52 additions and 15 deletions

View File

@ -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 <ethereum address> [<profile IPFS hash>]
### add-proposal.js
Adds a new proposal for an existing contributor
$ 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 <ethereum address>
### seeds.js
Run seeds defined in `config/seeds.js`.
$ truffle exec scripts/seeds.js
or
$ npm run seeds
## Upgradeable contracts

View File

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

View File

@ -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) => {
let result = await operator.addProposal(contributorId.toNumber(), 23, multihash.digest, multihash.hashFunction, multihash.size);
console.log('Proposal added, tx: ', result.tx);
});
callback();
});
}

View File

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

View File

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