-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_blocks.js
More file actions
60 lines (48 loc) · 1.58 KB
/
validate_blocks.js
File metadata and controls
60 lines (48 loc) · 1.58 KB
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
const fs = require('fs');
const readline = require('readline');
const INPUT_FILE = 'erc20_with_blocks.json';
const OUTPUT_FILE = 'duplicated_addresses.json';
async function findDuplicatedAddresses() {
const addressMap = new Map();
const fileStream = fs.createReadStream(INPUT_FILE, { encoding: 'utf8' });
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
let lineNumber = 0;
for await (const line of rl) {
lineNumber++;
if (line.trim() === '') continue;
try {
const obj = JSON.parse(line);
const address = obj.address;
const block = obj.number;
if (!address || block === undefined) {
console.warn(`Line ${lineNumber}: Missing address or number`);
continue;
}
if (!addressMap.has(address)) {
addressMap.set(address, []);
}
addressMap.get(address).push(block);
} catch (e) {
console.warn(`Line ${lineNumber}: Failed to parse JSON - ${e.message}`);
}
}
// Find duplicates (addresses with more than one block)
const duplicates = [];
for (const [address, blocks] of addressMap) {
if (blocks.length > 1) {
duplicates.push({
address: address,
blocks: blocks
});
}
}
// Write result to file
fs.writeFileSync(OUTPUT_FILE, JSON.stringify(duplicates, null, 2));
console.log(`Total unique addresses: ${addressMap.size}`);
console.log(`Duplicated addresses: ${duplicates.length}`);
console.log(`Result written to ${OUTPUT_FILE}`);
}
findDuplicatedAddresses().catch(console.error);