-
Notifications
You must be signed in to change notification settings - Fork 21
/
prepareCeremonyDapp.js
44 lines (34 loc) · 1.71 KB
/
prepareCeremonyDapp.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
const fs = require('fs');
const Constants = require("./utils/constants");
const constants = Constants.constants;
const utils = require("./utils/utils");
main()
function main() {
const pathToAddressesJSON = `${constants.pathToContractRepo}/${constants.addressesSourceFile}`;
const addresses = JSON.parse(fs.readFileSync(pathToAddressesJSON));
const addition = `\nconst local = { "KEYS_MANAGER_ADDRESS": "${addresses.KEYS_MANAGER_ADDRESS}" }`
let addressesFromDapp = fs.readFileSync(`${constants.pathToCeremonyDAppRepo}/src/utils/addresses.js`, 'utf8');
let lastImport = `import helpers from './helpers'`;
let lines = addressesFromDapp.split('\n');
lines = lines.map((line) => {
if (line.includes(lastImport)) {
return lastImport + addition
} else {
return line
}
})
addressesFromDapp = lines.join(`\n`);
addressesFromDapp = addressesFromDapp.replace('resolve({ addresses: json', 'resolve({ addresses: local')
fs.writeFileSync(`${constants.pathToCeremonyDAppRepo}/src/utils/addresses.js`, addressesFromDapp);
// Hardcode ABIs into helpers.js
const pathToKeysManagerJSON = `${constants.contractsFolder}/KeysManager.json`;
const keysManagerABI = JSON.stringify(JSON.parse(fs.readFileSync(pathToKeysManagerJSON)).abi).replace(/,/g, ', ');
const dappHelpers = `${constants.pathToCeremonyDAppRepo}/src/utils/helpers.js`;
let dappHelpersContent = fs.readFileSync(dappHelpers, 'utf8');
const abiAddition = `
if (contract === 'KeysManager') return ${keysManagerABI};`;
const lastGetABI = `function getABI(branch, contract) {`;
dappHelpersContent = dappHelpersContent.replace(lastGetABI, lastGetABI + abiAddition);
fs.writeFileSync(dappHelpers, dappHelpersContent);
console.log("Ceremony Repo is prepared");
}