Skip to content

Commit 8103df8

Browse files
committed
added contracts
1 parent 7b0e102 commit 8103df8

7 files changed

Lines changed: 13526 additions & 1137 deletions

File tree

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "dav-cli",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "${workspaceFolder}/src/index.js",
15+
"args": [
16+
"--start"
17+
]
18+
}
19+
]
20+
}

contracts/BasicMission.json

Lines changed: 5762 additions & 0 deletions
Large diffs are not rendered by default.

contracts/DAVToken.json

Lines changed: 3241 additions & 1123 deletions
Large diffs are not rendered by default.

contracts/Identity.json

Lines changed: 4475 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"prettier": "^1.17.0"
3535
},
3636
"preferGlobal": true
37-
}
37+
}

src/index.js

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
const program = require('commander');
24
const version = require('./lib/version');
35
const { EOL } = require('os');

src/lib/contracts.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
const chalk = require('chalk');
2+
const util = require('util');
23

3-
const deployContract = async (web3, contractDetails) => {
4+
const deployContract = async (web3, contractDetails, args) => {
45
const deployingAccount = (await web3.eth.getAccounts())[0];
56

67
// Create contract instance
78
const contract = new web3.eth.Contract(contractDetails.abi, {
8-
data: contractDetails.bytecode,
9+
data: contractDetails.bytecode
910
});
1011

1112
// Estimate gas
1213
const gasLimit = await web3.eth.estimateGas({
13-
data: contractDetails.bytecode,
14+
data: contractDetails.bytecode
1415
});
1516

1617
// Deploy contract
17-
return await contract.deploy().send({
18+
return await contract.deploy({ arguments: args }).send({
1819
from: deployingAccount,
19-
gasLimit: gasLimit,
20+
gasLimit: gasLimit
2021
});
2122
};
2223

24+
const contractJsonDAVToken = require('../../contracts/DAVToken.json');
25+
const contractJsonIdentity = require('../../contracts/Identity.json');
26+
const contractJsonBasicMission = require('../../contracts/BasicMission.json');
27+
2328
const deployContracts = async web3 => {
24-
const DAVToken = await deployContract(
25-
web3,
26-
require('../../contracts/DAVToken.json'),
27-
);
28-
console.log(
29-
'DAVToken contract: ' + chalk.green.bold(DAVToken.options.address),
30-
);
29+
try {
30+
const contractDAVToken = await deploySingleContract(web3, contractJsonDAVToken, null);
31+
const contractIdentity = await deploySingleContract(web3, contractJsonIdentity, [contractDAVToken.options.address]);
32+
const contractBasicMission = await deploySingleContract(web3, contractJsonBasicMission, [contractIdentity.options.address, contractDAVToken.options.address]);
33+
} catch (err) {
34+
console.error(util.inspect(err));
35+
}
3136
};
3237

38+
async function deploySingleContract(web3, contractJson, args) {
39+
console.log(`Deploying ${contractJson.contractName}...`);
40+
const contract = await deployContract(web3, contractJson, args);
41+
console.log(`${contractJson.contractName} contract: ${chalk.green.bold(contract.options.address)}`);
42+
return contract;
43+
}
44+
3345
module.exports = {
34-
deployContracts,
46+
deployContracts
3547
};

0 commit comments

Comments
 (0)