-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.js
99 lines (76 loc) · 3.3 KB
/
build.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
const yaml = require('js-yaml');
const fs = require('fs');
const { SHA3 } = require('sha3');
const axios = require('axios');
;(async () => {
const remoteBlocklist = yaml.load((await axios.get('https://raw.githubusercontent.com/phantom/blocklist/master/blocklist.yaml')).data).map((item) => {
return item.url || null;
}).filter(Boolean);
const remoteNftBlocklist = yaml.load((await axios.get('https://raw.githubusercontent.com/phantom/blocklist/master/nft-blocklist.yaml')).data).map((item) => {
return item.mint || null;
}).filter(Boolean);
const localBlocklist = yaml.load(fs.readFileSync('./lists/blocklist.yaml', 'utf8')).map((item) => {
return item.url || null;
}).filter(Boolean);
const localNftBlocklist = yaml.load(fs.readFileSync('./lists/nft-blocklist.yaml', 'utf8')).map((item) => {
if (item.mint) {
return item.mint;
}
if (item.tree) {
return item.tree;
}
return null;
}).filter(Boolean);
const localNftAllowlist = yaml.load(fs.readFileSync('./lists/nft-allowlist.yaml', 'utf8')).map((item) => {
if (item.mint) {
return item.mint;
}
if (item.tree) {
return item.tree;
}
if (item.collection) {
return item.collection;
}
return null;
}).filter(Boolean);
const localTreeFilterList = yaml.load(fs.readFileSync('./lists/tree-filterlist.yaml', 'utf8')).map((item) => {
if (item.tree) {
return item.tree;
}
return null;
}).filter(Boolean);
const localStringFilters = {};
const possibleFilters = ['symbol', 'symbolStartsWith', 'symbolEndsWith', 'symbolContains', 'name', 'nameStartsWith', 'nameEndsWith', 'nameContains'];
yaml.load(fs.readFileSync('./lists/token-blocklist.yaml', 'utf8')).map((item) => {
for (let i = 0; i < possibleFilters.length; i++) {
const filter = possibleFilters[i];
if (item[filter]) {
if (!localStringFilters[filter]) {
localStringFilters[filter] = [];
}
localStringFilters[filter].push(item[filter]);
break;
}
}
})
const combinedBlocklist = [...new Set([...remoteBlocklist, ...localBlocklist])];
const combinedNftBlocklist = [...new Set([...remoteNftBlocklist, ...localNftBlocklist])];
const nftAllowlistSet = new Set(localNftAllowlist);
const filteredBlocklist = combinedBlocklist.filter(url => !nftAllowlistSet.has(url));
const filteredNftBlocklist = combinedNftBlocklist.filter(mintOrTree => !nftAllowlistSet.has(mintOrTree));
const filteredTreeFilterlist = localTreeFilterList.filter(tree => !nftAllowlistSet.has(tree));
const data = {
'blocklist': filteredBlocklist,
'nftBlocklist': filteredNftBlocklist,
'whitelist': localNftAllowlist,
'fuzzylist': [],
'stringFilters': localStringFilters,
'treeFilters': filteredTreeFilterlist
}
const hash = new SHA3(256);
hash.update(JSON.stringify(data));
const contentHash = hash.digest('hex');
data['contentHash'] = contentHash;
fs.writeFileSync('./blocklist.json', JSON.stringify(data));
fs.writeFileSync('./content-hash.json', JSON.stringify(contentHash));
})();