generated from GIgako19929/ethereum_Giga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkNfts.js
107 lines (104 loc) · 2.18 KB
/
checkNfts.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
const fs = require('fs');
const nftsDirectory = './src/nfts';
const web3 = require('web3');
const path = require('path');
const validate = require('validate.js');
const validateObject = require('./validateObject');
const constraints = {
active: {
presence: {
allowEmpty: false
},
type: "boolean"
},
title: {
presence: {
allowEmpty: false
},
type: "string"
},
itemName: {
presence: {
allowEmpty: true
},
type: "string"
},
contractAddress: function(value) {
if (web3.utils.isAddress(value)) {
return null;
}
return {
presence: { message: 'Token Address missing' },
length: { is: 42 }
};
},
metadataAddress: {
presence: {
allowEmpty: false,
website: {
url: true
}
},
type: "string"
},
keys: {
presence: true,
type: "array"
},
imageKey: {
presence: {
allowEmpty: false
},
type: "string"
},
metadataKeys: {
presence: true,
type: "array"
},
ERC721Extension: {
presence: {
allowEmpty: false
},
type: "boolean"
},
ERC721Metadata: {
presence: {
allowEmpty: false
},
type: "boolean"
},
nonStandard: {
presence: {
allowEmpty: false
},
type: "boolean"
},
};
function checkNfts() {
fs.readdirSync(nftsDirectory).forEach(folder => {
fs.readdirSync(`${nftsDirectory}/${folder}`).forEach(file => {
if (
path.extname(file) === '.json' &&
web3.utils.isAddress(file.replace('.json', ''))
) {
const fullPath = `${nftsDirectory}/${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 ${nftsDirectory}/${folder}`
);
});
process.exit(1);
}
} else {
console.error('Incorrect file name or file extension');
process.exit(1);
}
});
});
process.exit(0);
}
checkNfts();