forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkToken.js
168 lines (165 loc) · 3.15 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
},
type: "string"
},
name: {
presence: {
allowEmpty: false
},
type: "string"
},
type: {
presence: {
allowEmpty: false,
},
inclusion: {
within: ['ERC20', 'ERC223', 'ERC721']
},
type: "string"
},
address: function(value) {
if (web3.utils.isAddress(value)) {
return null;
}
return {
presence: { message: 'Token Address missing' },
length: { is: 42 }
};
},
ens_address: {
presence: true,
type: "string"
},
decimals: {
presence: {
allowEmpty: false
},
type: "integer"
},
website: {
presence: true,
type: "string"
},
logo: {
presence: true
},
'logo.src': {
presence: true,
type: "string"
},
'logo.width': {
presence: true,
type: "string"
},
'logo.height': {
presence: true,
type: "string"
},
'logo.ipfs_hash': {
presence: true,
type: "string"
},
support: {
presence: true
},
'support.email': {
presence: true,
type: "string"
},
'support.url': {
presence: true,
type: "string"
},
social: {
presence: true
},
'social.blog': {
presence: true,
type: "string"
},
'social.chat': {
presence: true,
type: "string"
},
'social.facebook': {
presence: true,
type: "string"
},
'social.forum': {
presence: true,
type: "string"
},
'social.github': {
presence: true,
type: "string"
},
'social.gitter': {
presence: true,
type: "string"
},
'social.instagram': {
presence: true,
type: "string"
},
'social.linkedin': {
presence: true,
type: "string"
},
'social.reddit': {
presence: true,
type: "string"
},
'social.slack': {
presence: true,
type: "string"
},
'social.telegram': {
presence: true,
type: "string"
},
'social.twitter': {
presence: true,
type: "string"
},
'social.youtube': {
presence: true,
type: "string"
}
};
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();