forked from maximousblk/astatine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharverify-distribution.ts
77 lines (69 loc) · 1.63 KB
/
arverify-distribution.ts
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
import Arweave from "arweave";
import { all } from "ar-gql";
const client = new Arweave({
host: "arweave.net",
port: 443,
protocol: "https",
});
export const tokenAllocation = async (): Promise<{ address: string, weight: number }[]> => {
const height = (await client.network.getInfo()).height;
const query = `
query transactions($cursor: String, $fromBlock: Int) {
transactions(
tags: [
{ name: "Application", values: "ArVerify" }
{ name: "Action", values: "Verification" }
{ name: "Method", values: "Link" }
]
after: $cursor
block: { min: $fromBlock, max: ${height} }
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
recipient
block {
height
timestamp
}
owner {
address
}
}
}
}
}
`
let timestamp = new Date();
let yesterday = new Date(timestamp);
yesterday.setDate(yesterday.getDate() - 1);
const txs = await all(query)
const filtered = txs.filter((tx) => {
let timestamp = new Date(tx.node.block.timestamp * 1000);
return yesterday.getTime() <= timestamp.getTime()
})
const owners = filtered.map((tx) => {
return tx.node.owner.address
})
const allocations = {}
for (const owner of owners) {
if (!allocations[owner]) {
allocations[owner] = 1
} else {
allocations[owner] += 1
}
}
const astatine: { address: string, weight: number }[] = [];
for (const address of Object.keys(allocations)) {
astatine.push({
"address": address,
"weight": allocations[address]
})
}
console.log(astatine)
return astatine
}