-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
checkMasterFile.js
112 lines (110 loc) · 1.98 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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: [
'arb',
'akroma',
'ath',
'bsc',
'base',
'clo',
'egem',
'ella',
'esn',
'etc',
'eth',
'etho',
'etsc',
'exp',
'go',
'goerli',
'iolite',
'kov',
'mix',
'pol',
'matic',
'music',
'pirl',
'poa',
'reosc',
'rin',
'rop',
'rsk',
'rsk-test',
'tomo',
'tt',
'ubq',
'web',
'wtc',
'aa',
'aat',
'amoy',
'coti',
'holesky',
'xdc'
]
},
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'
},
symbol: {
presence: true,
type: 'string'
},
name: {
presence: true,
type: 'string'
},
decimals: {
presence: true,
type: 'number'
}
};
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();