forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recreateFiles.js
44 lines (42 loc) · 1.53 KB
/
recreateFiles.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 web3 = require('web3');
const utils = web3.utils;
const contractsDirectory = './src/contracts';
const tokensDirectory = './src/tokens';
function recreateContractFiles() {
fs.readdirSync(contractsDirectory).forEach(folderFile => {
fs.readdirSync(`${contractsDirectory}/${folderFile}`).forEach(file => {
const newFile = JSON.parse(
fs.readFileSync(`${contractsDirectory}/${folderFile}/${file}`)
);
const currentAddress = newFile.address;
newFile.address = utils.toChecksumAddress(currentAddress);
fs.unlinkSync(`${contractsDirectory}/${folderFile}/${file}`);
fs.writeFileSync(
`${contractsDirectory}/${folderFile}/${utils.toChecksumAddress(file.replace('.json', ''))}.json`,
JSON.stringify(newFile)
);
});
});
}
function recreateTokenFiles() {
fs.readdirSync(tokensDirectory).forEach(folderFile => {
fs.readdirSync(`${tokensDirectory}/${folderFile}`).forEach(file => {
const newFile = JSON.parse(
fs.readFileSync(`${tokensDirectory}/${folderFile}/${file}`)
);
const currentAddress = newFile.address;
newFile.address = utils.toChecksumAddress(currentAddress);
fs.unlinkSync(`${tokensDirectory}/${folderFile}/${file}`);
fs.writeFileSync(
`${tokensDirectory}/${folderFile}/${utils.toChecksumAddress(file.replace('.json', ''))}.json`,
JSON.stringify(newFile)
);
});
});
}
function recreateFiles() {
recreateContractFiles();
recreateTokenFiles();
}
module.exports = recreateFiles;