-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_deploy_contracts.js
82 lines (75 loc) · 2.81 KB
/
2_deploy_contracts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const LinniaHub = artifacts.require("./LinniaHub.sol")
const LinniaRoles = artifacts.require("./LinniaRoles.sol")
const LinniaRecords = artifacts.require("./LinniaRecords.sol")
const LinniaPermissions = artifacts.require("./LinniaPermissions.sol")
const MapDomain = artifacts.require("./MapDomain.sol");
const Zelp = artifacts.require("./Zelp.sol")
var fs = require('fs');
module.exports = (deployer, network, accounts) => {
const adminAddress = accounts[0]
let hubInstance, linniaRolesInstance, mapDomainInstance
// deploy the hub
deployer.deploy(LinniaHub).then(() => {
return LinniaHub.deployed()
}).then((_hubInstace) => {
hubInstance = _hubInstace
// deploy Roles
return deployer.deploy(LinniaRoles, hubInstance.address)
}).then(() => {
return LinniaRoles.deployed()
}).then((_linniaRolesInstance) => {
linniaRolesInstance = _linniaRolesInstance
// deploy Records
return deployer.deploy(LinniaRecords, hubInstance.address)
}).then(() => {
// deploy Permissions
return deployer.deploy(LinniaPermissions, hubInstance.address)
}).then(() => {
// set all the addresses in the hub
return hubInstance.setRolesContract(LinniaRoles.address)
}).then(() => {
return hubInstance.setRecordsContract(LinniaRecords.address)
}).then(() => {
return hubInstance.setPermissionsContract(LinniaPermissions.address)
}).then(() => {
return deployer.deploy(MapDomain, hubInstance.address)
}).then(() => {
return MapDomain.deployed();
}).then((_mapDomainInstance) => {
mapDomainInstance = _mapDomainInstance;
return linniaRolesInstance.registerProvider(mapDomainInstance.address, { from: adminAddress })
}).then((() => {
return deployer.deploy(Zelp, mapDomainInstance.address)
})).then(() => {
return Zelp.deployed();
}).then((_zelpInstance) => {
console.log(`export ZELP_ADDRESS=${_zelpInstance.address}`);
fs.readFile('build/contracts/Zelp.json', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
let contract = {
address: _zelpInstance.address,
abi: JSON.parse(data).abi
};
fs.writeFile("../web/abi.json", JSON.stringify(contract), function(err) {
if(err) {
return console.log(err);
}
fs.writeFile("../serverless/abi.json", JSON.stringify(contract), function(err) {
if(err) {
return console.log(err);
}
console.log("ABI files saved!");
});
});
});
fs.readFile('../serverless/default_records.json', 'utf8', function (err, data) {
const records = JSON.parse(data);
for (let i = 0; i < records.length; ++i) {
const record = records[i];
_zelpInstance.add(record.id, record.endpoint, record.restaurant);
}
});
})
}