From d46102ca3a6850fa96d1546d2f898fdd6de270c5 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 8 Apr 2019 16:34:37 -0400 Subject: [PATCH] use new function syntax for afterDeploy - --- config/contracts.js | 52 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/config/contracts.js b/config/contracts.js index ecba7f5..82ed9c4 100644 --- a/config/contracts.js +++ b/config/contracts.js @@ -1,7 +1,7 @@ const options = require("../app/js/contributors"); function getContributors () { - var addresses = options.map(a => "'"+ a.value + "'"); + var addresses = options.map(a => a.value); if ( new Set(addresses).size !== addresses.length ) { throw 'duplicates in options'; } @@ -108,16 +108,46 @@ module.exports = { } ] }, - "afterDeploy": [ - // Give Tokens to Meritocracy Owner - "SNT.methods.generateTokens('$accounts[0]', '1000000000000000000000').send()", - // Add All Contributors - "Meritocracy.methods.addContributors([" + getContributors().toString() + "]).send()", - // Allocate Owner Tokens - "SNT.methods.approve('$Meritocracy', '1000000000000000000000').send()", - "Meritocracy.methods.allocate('1000000000000000000000').send()", - ] + afterDeploy: async (deps) => { + try { + const {SNT, Meritocracy} = deps.contracts; + const addresses = await deps.web3.eth.getAccounts(); + const mainAccount = addresses[0]; + const balance = await SNT.methods.balanceOf(mainAccount).call(); + if (balance !== '0') { + return; + } + const tokens = '1000000000000000000000'; + + console.log('Generating tokens for the main account...'); + const generateTokens = SNT.methods.generateTokens(mainAccount, tokens); + let gas = await generateTokens.estimateGas({from: mainAccount}); + await generateTokens.send({from: mainAccount, gas}); + + // Add All Contributors + console.log('Adding all tokens...'); + const addContributors = Meritocracy.methods.addContributors(getContributors()); + gas = await addContributors.estimateGas({from: mainAccount}); + await addContributors.send({from: mainAccount, gas}); + + // Allocate Owner Tokens + console.log('Approving token transfer...'); + const approve = SNT.methods.approve(Meritocracy.options.address, tokens); + gas = await approve.estimateGas({from: mainAccount}); + await approve.send({from: mainAccount, gas}); + + console.log('Allocating tokens...'); + const allocate = Meritocracy.methods.allocate(tokens); + gas = await allocate.estimateGas({from: mainAccount}); + await allocate.send({from: mainAccount, gas}); + + console.log('All done!') + } catch (e) { + console.log("------- Error in after deploy ------- "); + console.dir(e); + } + } }, // merges with the settings in default @@ -183,4 +213,4 @@ module.exports = { // "embark run custom_name" or "embark blockchain custom_name" //custom_name: { //} -}; \ No newline at end of file +};