Skip to content

Commit

Permalink
deploy all contracts works
Browse files Browse the repository at this point in the history
  • Loading branch information
srfrnk committed Dec 20, 2019
1 parent 8103df8 commit 4a6abde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dav-cli": "bin/dav-cli.js"
},
"scripts": {
"start": "./bin/dav-cli.js",
"start": "./bin/dav-cli.js --start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
Expand Down
28 changes: 17 additions & 11 deletions src/controllers/blockchain.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
const ganache = require('ganache-cli');
const { deployContracts } = require('../lib/contracts');
const chalk = require('chalk');
const util = require('util');

const startTestnet = (port = 8545) => {
const server = ganache.server();
server.listen(port, () => {
console.log(
'Local Ethereum testnet started on ' +
chalk.blue.bold.underline(`http://localhost:${port}`),
);
server.listen(port, async () => {
try {
console.log(
'Local Ethereum testnet started on ' +
chalk.blue.bold.underline(`http://localhost:${port}`)
);

const Web3 = require('web3');
const web3 = new Web3(
new Web3.providers.HttpProvider(`http://localhost:${port}`),
);
const Web3 = require('web3');
const web3 = new Web3(
new Web3.providers.HttpProvider(`http://localhost:${port}`)
);

deployContracts(web3);
await deployContracts(web3);
} catch (err) {
console.error(util.inspect(err));
process.exit(0);
}
});
};

module.exports = {
startTestnet,
startTestnet
};
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

const program = require('commander');
const version = require('./lib/version');
const { EOL } = require('os');
Expand Down
13 changes: 4 additions & 9 deletions src/lib/contracts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const chalk = require('chalk');
const util = require('util');

const deployContract = async (web3, contractDetails, args) => {
const deployingAccount = (await web3.eth.getAccounts())[0];
Expand All @@ -17,7 +16,7 @@ const deployContract = async (web3, contractDetails, args) => {
// Deploy contract
return await contract.deploy({ arguments: args }).send({
from: deployingAccount,
gasLimit: gasLimit
gasLimit: gasLimit * 3
});
};

Expand All @@ -26,13 +25,9 @@ const contractJsonIdentity = require('../../contracts/Identity.json');
const contractJsonBasicMission = require('../../contracts/BasicMission.json');

const deployContracts = async web3 => {
try {
const contractDAVToken = await deploySingleContract(web3, contractJsonDAVToken, null);
const contractIdentity = await deploySingleContract(web3, contractJsonIdentity, [contractDAVToken.options.address]);
const contractBasicMission = await deploySingleContract(web3, contractJsonBasicMission, [contractIdentity.options.address, contractDAVToken.options.address]);
} catch (err) {
console.error(util.inspect(err));
}
const contractDAVToken = await deploySingleContract(web3, contractJsonDAVToken, null);
const contractIdentity = await deploySingleContract(web3, contractJsonIdentity, [contractDAVToken.options.address]);
const contractBasicMission = await deploySingleContract(web3, contractJsonBasicMission, [contractIdentity.options.address, contractDAVToken.options.address]);
};

async function deploySingleContract(web3, contractJson, args) {
Expand Down

0 comments on commit 4a6abde

Please sign in to comment.