forked from phantom/blocklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
75 lines (63 loc) · 2.84 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
const yaml = require('js-yaml');
const fs = require('fs');
const { SHA3 } = require('sha3');
// Read local yaml files for blocklists
const solBlocklist = yaml.load(fs.readFileSync('./blocklist.yaml', 'utf8'));
const ethBlocklist = yaml.load(fs.readFileSync('./eth-blocklist.yaml', 'utf8'));
const nftBlocklist = yaml.load(fs.readFileSync('./nft-blocklist.yaml', 'utf8'));
const whitelist = yaml.load(fs.readFileSync('./whitelist.yaml', 'utf8'));
const fuzzylist = yaml.load(fs.readFileSync('./fuzzylist.yaml', 'utf8'));
// Multichain blocklist concatenates each blockchains blocklist
const solBlocklistArray = solBlocklist.map((item) => { return item.url });
const ethBlocklistArray = ethBlocklist.map((item) => { return item.url });
// Important: Solana list must be at the head because of the way the cursor works
// TODO: This is jank, we should fix this
const multichainBlocklistArray = solBlocklistArray.concat(ethBlocklistArray);
// Construct output files for solana only
const data = {
"blocklist": solBlocklistArray,
"nftBlocklist": nftBlocklist.map((item) => { return item.mint }),
"whitelist": whitelist.map((item) => { return item.url }),
"fuzzylist": fuzzylist.map((item) => { return item.url })
};
const hash = new SHA3(256);
hash.update(JSON.stringify(data));
const contentHash = hash.digest('hex');
const dataFull = {
"blocklist": solBlocklist,
"nftBlocklist": nftBlocklist,
"whitelist": whitelist,
"fuzzylist": fuzzylist
};
data["contentHash"] = contentHash;
dataFull["contentHash"] = contentHash;
fs.writeFileSync("./blocklist.json", JSON.stringify(data));
fs.writeFileSync("./content-hash.json", JSON.stringify(contentHash));
fs.writeFileSync("./blocklist-full.json", JSON.stringify(dataFull));
// Construct output files for multichain
const dataMultichain = {
"blocklist": multichainBlocklistArray,
"nftBlocklist": nftBlocklist.map((item) => { return item.mint }),
"whitelist": whitelist.map((item) => { return item.url }),
"fuzzylist": fuzzylist.map((item) => { return item.url })
};
const hashMultichain = new SHA3(256);
hashMultichain.update(JSON.stringify(data));
const contentHashMultichain = hashMultichain.digest('hex');
const dataMultichainFull = {
// TODO: Fix so we don't rely on ordering
"blocklist": solBlocklist.concat(ethBlocklist),
"nftBlocklist": nftBlocklist,
"whitelist": whitelist,
"fuzzylist": fuzzylist,
"ethBlocklist": ethBlocklist,
"solBlocklist": solBlocklist
};
dataMultichain["contentHash"] = contentHashMultichain;
dataMultichainFull["contentHash"] = contentHashMultichain;
if (!fs.existsSync("./multichain")){
fs.mkdirSync("./multichain");
}
fs.writeFileSync("./multichain/blocklist.json", JSON.stringify(dataMultichain));
fs.writeFileSync("./multichain/content-hash.json", JSON.stringify(contentHashMultichain));
fs.writeFileSync("./multichain/blocklist-full.json", JSON.stringify(dataMultichainFull));