forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkToken.js
143 lines (140 loc) · 2.66 KB
/
checkToken.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const fs = require('fs');
const tokensDirectory = './src/tokens';
const web3 = require('web3');
const path = require('path');
const validate = require('validate.js');
const validateObject = require('./validateObject');
const constraints = {
symbol: {
presence: {
allowEmpty: false
}
},
name: {
presence: {
allowEmpty: false
}
},
type: {
presence: {
allowEmpty: false,
},
inclusion: {
within: ['ERC20', 'ERC223', 'ERC721']
}
},
address: function(value) {
if (web3.utils.isAddress(value)) {
return null;
}
return {
presence: { message: 'Token Address missing' },
length: { is: 42 }
};
},
ens_address: {
presence: true
},
decimals: {
presence: {
allowEmpty: false
}
},
website: {
presence: true
},
logo: {
presence: true
},
'logo.src': {
presence: true
},
'logo.width': {
presence: true
},
'logo.height': {
presence: true
},
'logo.ipfs_hash': {
presence: true
},
support: {
presence: true
},
'support.email': {
presence: true
},
'support.url': {
presence: true
},
social: {
presence: true
},
'social.blog': {
presence: true
},
'social.chat': {
presence: true
},
'social.facebook': {
presence: true
},
'social.forum': {
presence: true
},
'social.github': {
presence: true
},
'social.gitter': {
presence: true
},
'social.instagram': {
presence: true
},
'social.linkedin': {
presence: true
},
'social.reddit': {
presence: true
},
'social.slack': {
presence: true
},
'social.telegram': {
presence: true
},
'social.twitter': {
presence: true
},
'social.youtube': {
presence: true
}
};
function checkToken() {
fs.readdirSync(tokensDirectory).forEach(folder => {
fs.readdirSync(`${tokensDirectory}/${folder}`).forEach(file => {
if (
path.extname(file) === '.json' &&
web3.utils.isAddress(file.replace('.json', ''))
) {
const fullPath = `${tokensDirectory}/${folder}/${file}`;
const obj = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
validateObject(constraints, obj, fullPath);
if (validate(obj, constraints) !== undefined) {
const errs = validate(obj, constraints);
Object.keys(errs).forEach(key => {
console.error(
`${errs[key][0]} for ${file} in ${tokensDirectory}/${folder}`
);
});
process.exit(1);
}
} else {
console.error('Incorrect file name or file extension');
process.exit(1);
}
});
});
process.exit(0);
}
checkToken();