-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
171 lines (152 loc) · 6.23 KB
/
index.js
File metadata and controls
171 lines (152 loc) · 6.23 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
// libraries
// modules
// constants
// variables
// functions
const getDistributionOverTime = async (httpsRateLimit, historyChunkSize,
timeChunkFn, knownAccountTypeMap, sourceAccount,
amountSentByTimeChunkAndSrcDestTypeMap,
amountReceivedByTimeChunkAndSrcDestTypeMap,
whalewatch, debug, verbose, nbr, max, tier) => {
let next;
let stop = false;
let srcType = tier;
if (knownAccountTypeMap.has(sourceAccount)) {
srcType = knownAccountTypeMap.get(sourceAccount);
}
// console.log('knownAccountTypeMap', knownAccountTypeMap);
const processedBlockHashSet = new Set();
while (!stop) {
// by default stop.
stop = true;
const accountHistoryReq = {
action: 'account_history',
account: sourceAccount,
count: historyChunkSize,
reverse: true,
raw: true,
};
// console.log('accountHistoryReq', accountHistoryReq);
if (next) {
accountHistoryReq.head = next;
}
// do not reuse next hash
next = undefined;
const accountHistoryResp = await httpsRateLimit.sendRequest(accountHistoryReq);
// console.log('accountHistoryResp', accountHistoryResp);
if (accountHistoryResp.history) {
if (accountHistoryResp.history.length > 0) {
for (const historyElt of accountHistoryResp.history) {
// for (let historyIx = 0; historyIx < accountHistoryResp.history.length; historyIx++) {
// const historyElt = accountHistoryResp.history[historyIx];
// console.log('historyElt', historyElt);
if (!processedBlockHashSet.has(historyElt.hash)) {
processedBlockHashSet.add(historyElt.hash);
const destAccount = historyElt.account;
let destType = tier;
// start EXCHANGED
// if(srcType == 'exchange') {
// destType = 'exchanged-to-' + tier;
// }
// stop EXCHANGED
if (knownAccountTypeMap.has(destAccount)) {
destType = knownAccountTypeMap.get(destAccount);
} else {
const accountInfoReq = {
action: 'account_info',
account: destAccount,
representative: true,
weight: true,
pending: true,
};
const accountInfoResp = await httpsRateLimit.sendRequest(accountInfoReq);
// console.log('accountInfoResp', accountInfoResp);
if (accountInfoResp.representative == 'ban_1tipbotgges3ss8pso6xf76gsyqnb69uwcxcyhouym67z7ofefy1jz7kepoy') {
destType = 'distributed-to-known';
// console.log('tipbot', 'historyElt', historyElt);
// console.log('tipbot', 'accountInfoResp', historyElt);
// save type so we dont ahve to redo API call.
}
if (destAccount !== undefined) {
knownAccountTypeMap.set(destAccount, destType);
// } else {
// console.log('historyElt', historyElt);
}
}
const amount = parseFloat(historyElt.amount_decimal);
const timeMs = historyElt.local_timestamp * 1000;
// console.log('local_timestamp', getDate(timeMs));
const localTimeChunk = timeChunkFn(timeMs);
// console.log('historyElt.hash', historyElt.hash, localTimeChunk);
// console.log('localTimeChunk', localTimeChunk);
const amountBySrcDestTypeToMap = (map) => {
let amountBySrcDestTypeMap;
if (map.has(localTimeChunk)) {
amountBySrcDestTypeMap = map.get(localTimeChunk);
} else {
amountBySrcDestTypeMap = new Map();
map.set(localTimeChunk, amountBySrcDestTypeMap);
}
let amountByDestTypeMap;
if (amountBySrcDestTypeMap.has(srcType)) {
amountByDestTypeMap = amountBySrcDestTypeMap.get(srcType);
} else {
amountByDestTypeMap = new Map();
amountBySrcDestTypeMap.set(srcType, amountByDestTypeMap);
}
let oldAmount = 0.0;
if (amountByDestTypeMap.has(destType)) {
oldAmount = amountByDestTypeMap.get(destType);
}
const newAmount = oldAmount + amount;
amountByDestTypeMap.set(destType, newAmount);
};
if ((historyElt.type == 'state') && (historyElt.subtype == 'send')) {
/* istanbul ignore if */
if (amount > 1000000) {
if (verbose) {
console.log('distribution calculation CONTINUE',
nbr, 'of', max, 'whalewatch', localTimeChunk, amount,
srcType, '=>', destType, 'hash', historyElt.hash,
'sourceAccount', sourceAccount, 'destAccount', destAccount);
}
whalewatch.push({
amount: amount,
hash: historyElt.hash,
timeChunk: localTimeChunk,
srcType: srcType,
destType: destType,
sourceAccount: sourceAccount,
destAccount: destAccount,
});
}
amountBySrcDestTypeToMap(amountSentByTimeChunkAndSrcDestTypeMap);
}
if ((historyElt.type == 'state') && (historyElt.subtype == 'receive')) {
amountBySrcDestTypeToMap(amountReceivedByTimeChunkAndSrcDestTypeMap);
}
}
};
}
}
// console.log('accountHistoryResp.next', accountHistoryResp.next, accountHistoryResp.history.length);
if (accountHistoryResp.next != undefined) {
next = accountHistoryResp.next;
}
if (next !== undefined) {
stop = false;
}
if (debug) {
// console.log('processedBlockHashSet.size', processedBlockHashSet.size, 'of', historyChunkSize);
if (processedBlockHashSet.size > historyChunkSize) {
stop = true;
}
}
/* istanbul ignore if */
if (verbose) {
console.log('distribution calculation CONTINUE', nbr, 'of', max, processedBlockHashSet.size, 'blocks', 'stop', stop, 'next', accountHistoryResp.next);
}
}
};
exports.getDistributionOverTime = getDistributionOverTime;