-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
98 lines (88 loc) · 2.68 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
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
const fetch = require('node-fetch');
const fs = require('fs');
const path = require('path');
const pAll = require('p-all');
const colors = require ('colors');
// Function to fetch points data for a given address
async function fetchPointsData(address) {
const headers = {
Host: 'metadata.p.rainbow.me',
Accept: 'application/json',
'User-Agent': 'Rainbow/28 CFNetwork/1404.0.5 Darwin/22.3.0',
Connection: 'keep-alive',
'Accept-Language': 'en-GB,en;q=0.9',
Authorization: 'Bearer 6CDGNtUsiUyAukyFV9Mx2dsqMTR9qyUB',
'Content-Type': 'application/json',
};
const graphql = JSON.stringify({
query: `query getPointsDataForWallet($address: String!) {
points(address: $address) {
error {
message
type
}
user {
referralCode
earnings {
total
}
stats {
position {
current
}
}
}
}
}`,
variables: { address },
});
const requestOptions = {
method: 'POST',
headers: headers,
body: graphql,
redirect: 'follow',
};
try {
const response = await fetch(
'https://metadata.p.rainbow.me/v1/graph',
requestOptions
);
const result = await response.json();
return result;
} catch (error) {
console.error('Error fetching data for address:', address, error);
return null;
}
}
// Function to process each address
async function processAddresses(file) {
const addresses = fs.readFileSync(file, 'utf8').split('\n');
const outputFile = path.join(__dirname, 'output.txt');
const tasks = addresses.map((address) => {
return async () => {
if (address) {
try {
const { data } = await fetchPointsData(address.trim());
if (data?.points?.error) {
console.log(data.points.error.message);
return;
}
if (data?.points?.user) {
const balance = data.points.user.earnings.total;
if (balance > 0) {
const log = `Address: ${address}, Points Balance: ${balance}`;
console.log(log.green);
fs.appendFileSync(outputFile, log + '\n');
}
}
} catch (error) {
console.error('Error fetching data for address:', address, error);
}
}
};
});
// Run tasks with a concurrency of 3
await pAll(tasks, { concurrency: 1 });
}
// Replace 'addresses.txt' with the path to your file containing the addresses
processAddresses('addresses.txt');