forked from safuco/ZKsync-Fast-Airdrop-Checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (62 loc) · 2.03 KB
/
index.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
const fs = require('fs');
const colors = require('colors');
// Function to load the eligibility list
function loadEligibilityList(filePath) {
return new Promise((resolve, reject) => {
const eligibilitySet = new Map();
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
reject(err);
} else {
const rows = data.split('\n');
rows.forEach((row) => {
const [address, amount] = row.split(',');
if (address && amount) {
eligibilitySet.set(address.trim().toLowerCase(), amount.trim());
}
});
resolve(eligibilitySet);
}
});
});
}
// Function to load wallet addresses
function loadWalletAddresses(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
reject(err);
} else {
const walletAddresses = data.split('\n').map((line) => line.trim());
resolve(walletAddresses);
}
});
});
}
// Function to check eligibility and log eligible addresses
async function checkEligibility(eligibilityFilePath, walletAddressesFilePath) {
try {
const eligibilitySet = await loadEligibilityList(eligibilityFilePath);
const walletAddresses = await loadWalletAddresses(walletAddressesFilePath);
walletAddresses.forEach((address) => {
const lowerAddress = address.toLowerCase();
if (eligibilitySet.has(lowerAddress)) {
const amount = eligibilitySet.get(lowerAddress);
console.log(colors.green(`${address} - Eligible Amount: ${amount}`));
fs.appendFileSync(
'eligible_addresses.txt',
`${address.trim()}\t${amount}\n`
);
} else {
console.log(`${address} is not eligible`);
}
});
} catch (error) {
console.error(colors.red('Error:'), error);
}
}
// Paths to your files
const eligibilityFilePath = 'eligibility_list.csv';
const walletAddressesFilePath = 'wallet_addresses.txt';
// Check eligibility
checkEligibility(eligibilityFilePath, walletAddressesFilePath);