Skip to content

Commit

Permalink
added contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
srfrnk committed Dec 19, 2019
1 parent 7b0e102 commit 8103df8
Show file tree
Hide file tree
Showing 7 changed files with 13,526 additions and 1,137 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "dav-cli",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/index.js",
"args": [
"--start"
]
}
]
}
5,762 changes: 5,762 additions & 0 deletions contracts/BasicMission.json

Large diffs are not rendered by default.

4,364 changes: 3,241 additions & 1,123 deletions contracts/DAVToken.json

Large diffs are not rendered by default.

4,475 changes: 4,475 additions & 0 deletions contracts/Identity.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"prettier": "^1.17.0"
},
"preferGlobal": true
}
}
2 changes: 2 additions & 0 deletions src/index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

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

const deployContract = async (web3, contractDetails) => {
const deployContract = async (web3, contractDetails, args) => {
const deployingAccount = (await web3.eth.getAccounts())[0];

// Create contract instance
const contract = new web3.eth.Contract(contractDetails.abi, {
data: contractDetails.bytecode,
data: contractDetails.bytecode
});

// Estimate gas
const gasLimit = await web3.eth.estimateGas({
data: contractDetails.bytecode,
data: contractDetails.bytecode
});

// Deploy contract
return await contract.deploy().send({
return await contract.deploy({ arguments: args }).send({
from: deployingAccount,
gasLimit: gasLimit,
gasLimit: gasLimit
});
};

const contractJsonDAVToken = require('../../contracts/DAVToken.json');
const contractJsonIdentity = require('../../contracts/Identity.json');
const contractJsonBasicMission = require('../../contracts/BasicMission.json');

const deployContracts = async web3 => {
const DAVToken = await deployContract(
web3,
require('../../contracts/DAVToken.json'),
);
console.log(
'DAVToken contract: ' + chalk.green.bold(DAVToken.options.address),
);
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));
}
};

async function deploySingleContract(web3, contractJson, args) {
console.log(`Deploying ${contractJson.contractName}...`);
const contract = await deployContract(web3, contractJson, args);
console.log(`${contractJson.contractName} contract: ${chalk.green.bold(contract.options.address)}`);
return contract;
}

module.exports = {
deployContracts,
deployContracts
};

0 comments on commit 8103df8

Please sign in to comment.