-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial.js
87 lines (71 loc) · 2.19 KB
/
initial.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
const { arGql } = require("ar-gql");
const { writeFileSync, fstat, write, writeFile } = require("fs");
const { join } = require("path");
const gql = arGql("https://arweave-search.goldsky.com/graphql");
(async () => {
let weeks = [];
const getWeekNum = (time) => {
const start = new Date(time.getFullYear(), 0, 1);
const days = Math.floor((time - start) / (24 * 60 * 60 * 1000));
const weekNumber = Math.ceil(days / 7);
return weekNumber;
}
const loop = async (cursor) => {
const res = await gql.run(`query($cursor: String) {
transactions(
tags: [{ name: "Signing-Client", values: "ArConnect" }]
sort: HEIGHT_ASC
first: 100
after: $cursor
) {
edges {
node {
owner {
address
}
block {
timestamp
}
}
cursor
}
pageInfo {
hasNextPage
}
}
}`, { cursor });
for (const { node } of res.data.transactions.edges) {
if (weeks.find((w) => w.addresses.includes(node.owner.address))) {
continue;
}
const time = new Date(node.block.timestamp * 1000)
let weekNumber = getWeekNum(time);
if (weekNumber === 0) {
time.setDate(time.getDate() - 7);
weekNumber = getWeekNum(time) + 1;
}
const weekInArray = weeks.find((w) => w.week === time.getFullYear() + "-" + weekNumber);
if (!weekInArray) {
weeks.push({
week: time.getFullYear() + "-" + weekNumber,
count: 0,
addresses: [node.owner.address]
});
} else {
weekInArray.addresses.push(node.owner.address);
}
}
if (res.data.transactions.pageInfo.hasNextPage) {
await loop(res.data.transactions.edges[res.data.transactions.edges.length - 1].cursor);
}
};
await loop();
for (let i = 0; i < weeks.length; i++) {
if (i === 0) {
weeks[i].count = weeks[i].addresses.length;
} else {
weeks[i].count += weeks[i - 1].count + weeks[i].addresses.length;
}
}
writeFileSync(join(__dirname, "data.json"), new TextEncoder().encode(JSON.stringify(weeks, null, 2)));
})();