forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkMasterFile.js
90 lines (87 loc) · 1.6 KB
/
checkMasterFile.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
83
84
85
86
87
88
89
90
const fs = require('fs');
const filePath = './dist/master-file.json';
const web3 = require('web3');
const validate = require('validate.js');
const validateObject = require('./validateObject');
const constraints = {
network: {
presence: {
allowEmpty: false,
},
inclusion: {
within: [ 'akroma',
'ath',
'clo',
'egem',
'ella',
'esn',
'etc',
'eth',
'etho',
'etsc',
'exp',
'go',
'goerli',
'iolite',
'kov',
'mix',
'music',
'pirl',
'poa',
'reosc',
'rin',
'rop',
'rsk',
'rsk-test',
'tomo',
'tt',
'ubq',
'web',
'wtc' ]
},
type: "string"
},
contract_address: function(value) {
if (web3.utils.isAddress(value)) {
return null;
}
return {
presence: { message: 'Token Address missing' },
length: { is: 42 }
};
},
icon: {
presence: true,
type: "string"
},
icon_png: {
presence: true,
type: "string"
},
link: {
presence: {
allowEmpty: false
},
type: "string"
},
website: {
presence: true,
type: "string"
}
};
function checkMasterFile() {
const arr = JSON.parse(fs.readFileSync(filePath));
arr.forEach(item => {
validateObject(constraints, item, filePath);
if (validate(item, constraints) !== undefined) {
const errs = validate(item, constraints);
Object.keys(errs).forEach(key => {
console.error(
`${errs[key][0]} for Master File`
);
});
process.exit(1);
}
});
}
checkMasterFile();