-
Notifications
You must be signed in to change notification settings - Fork 3
/
calculate-revenue.js
46 lines (40 loc) · 1.45 KB
/
calculate-revenue.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
require('dotenv').config();
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
const tx = require('@stacks/transactions');
const utils = require('./utils');
const network = utils.resolveNetwork();
const axios = require('axios');
const apiUrl = 'https://api.hiro.so';
const sinceBlock = 102202;
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
async function getTransactions() {
const unstackContract = 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-freddie-v1-1';
const baseUrl = `${apiUrl}/extended/v1/address/${unstackContract}/transactions?limit=50`;
console.log(baseUrl);
let response = await axios.get(baseUrl);
let results = response.data['results'];
const total = parseInt(response.data['total'], 10);
console.log('got', total, 'results');
let offset = 50;
while (offset <= total && results?.length > 0) {
console.log('fetched', results.length, 'transactions with offset', offset);
await asyncForEach(results, async (result) => {
if (
result['tx_status'] === 'success' &&
result['tx_type'] === 'contract_call' &&
result['contract_call']['function_name'] === 'redeem-tokens'
) {
console.log(result);
}
});
offset += 50;
const url = `${baseUrl}&offset=${offset}`;
response = await axios.get(url);
results = response.data['results'];
}
}
getTransactions();