Skip to content

Commit 4aa0c07

Browse files
committed
feat: calculate absolute balance delta
1 parent d880952 commit 4aa0c07

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

utils/package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"bignumber.js": "^9.0.1",
1414
"dotenv": "^10.0.0",
15+
"extra-bigint": "0.0.62",
1516
"getopts": "^2.3.0",
1617
"pg": "^8.2.1",
1718
"pg-copy-streams": "^5.1.1",

utils/src/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as dotenv from 'dotenv';
22
import * as getopts from 'getopts';
3+
import * as bigint from 'extra-bigint';
34
import { table } from 'table';
45
import { StacksCoreRpcClient } from '../../src/core-rpc/client';
56
import { PgDataStore } from '../../src/datastore/postgres-store';
@@ -28,7 +29,8 @@ type TableCellValue = string | number | bigint | undefined;
2829
async function printTopAccountBalances(count: number, blockHeight: number) {
2930
const db = await PgDataStore.connect(true);
3031

31-
console.log(`Calculating balances for top ${count} accounts at block height ${blockHeight}...`);
32+
const heightText = blockHeight == 0 ? 'chain tip' : `block height ${blockHeight}`;
33+
console.log(`Calculating balances for top ${count} accounts at ${heightText}...`);
3234
const blockInfo = await db.query(async client => {
3335
const result = await client.query<BlockInfo>(
3436
`
@@ -95,10 +97,16 @@ async function printTopAccountBalances(count: number, blockHeight: number) {
9597
await Promise.all(dbBalances.concat(nodeBalances));
9698

9799
const tabularData: TableCellValue[][] = [
98-
['event count', 'address', 'api balance', 'node balance'],
100+
['event count', 'address', 'api balance', 'node balance', 'delta'],
99101
];
100102
addressBalances.forEach(item => {
101-
tabularData.push([item.count, item.address, item.apiBalance, item.nodeBalance]);
103+
tabularData.push([
104+
item.count,
105+
item.address,
106+
item.apiBalance,
107+
item.nodeBalance,
108+
bigint.abs((item.apiBalance ?? BigInt(0)) - (item.nodeBalance ?? BigInt(0))),
109+
]);
102110
});
103111
console.log(table(tabularData));
104112

0 commit comments

Comments
 (0)