Skip to content

Commit 01ac182

Browse files
committed
Merge branch 'main' into release/4.0
2 parents 83c0408 + 104e43e commit 01ac182

File tree

5 files changed

+154
-39
lines changed

5 files changed

+154
-39
lines changed

.github/workflows/dev.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: DEV Build with Node.js CI
2+
3+
on:
4+
push:
5+
branches: [ "3.5.0-esm" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [22.x, 23.x]
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
cache: 'npm'
20+
- run: npm ci --ignore-scripts
21+
- run: npm run build
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { timedQuery } from "../../../helpers/functions";
2+
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3+
import { getSkipLimit } from "../../v2-history/get_actions/functions";
4+
5+
async function getTopHolders(fastify: FastifyInstance, request: FastifyRequest) {
6+
7+
const query: any = request.query;
8+
9+
const response: any = {
10+
contract: query.contract,
11+
symbol: undefined,
12+
holders: []
13+
};
14+
15+
const { skip, limit } = getSkipLimit(request.query);
16+
17+
const maxDocs = fastify.manager.config.api.limits.get_top_holders ?? 500;
18+
19+
const terms: any[] = [];
20+
21+
22+
if (query.contract) {
23+
terms.push({ "term": { "code": { "value": query.contract } } });
24+
}
25+
26+
if (query.symbol) {
27+
terms.push({ "term": { "symbol": { "value": query.symbol } } });
28+
response.symbol = query.symbol;
29+
}
30+
31+
32+
const stateResult = await fastify.elastic.search<any>({
33+
"index": fastify.manager.chain + '-table-accounts-*',
34+
"size": (limit > maxDocs ? maxDocs : limit) || 50,
35+
"from": skip || 0,
36+
body: {
37+
sort: {
38+
amount: {
39+
order: "desc"
40+
}
41+
},
42+
query: { bool: { "must": terms } }
43+
}
44+
});
45+
46+
response.holders = stateResult.body.hits.hits.map((doc: any) => {
47+
return {
48+
owner: doc._source.scope,
49+
amount: doc._source.amount,
50+
symbol: doc._source.symbol,
51+
updated_on: doc._source.block_num
52+
};
53+
});
54+
55+
return response;
56+
57+
}
58+
59+
export function getTopHoldersHandler(fastify: FastifyInstance, route: string) {
60+
return async (request: FastifyRequest, reply: FastifyReply) => {
61+
reply.send(await timedQuery(getTopHolders, fastify, request, route));
62+
}
63+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {FastifyInstance} from "fastify";
2+
import {addApiRoute, extendQueryStringSchema, getRouteName} from "../../../helpers/functions";
3+
import { getTopHoldersHandler } from "./get_top_holders";
4+
5+
export default function (fastify: FastifyInstance, opts: any, next) {
6+
const schema = {
7+
description: 'get the list of top holders for a given token',
8+
summary: 'get top token holders',
9+
tags: ['accounts'],
10+
querystring: extendQueryStringSchema({
11+
"contract": {
12+
description: 'token contract account name',
13+
type: 'string',
14+
minLength: 1,
15+
maxLength: 12
16+
},
17+
"symbol": {
18+
description: 'filter by token symbol',
19+
type: 'string'
20+
},
21+
}, ["contract"])
22+
};
23+
addApiRoute(
24+
fastify,
25+
'GET',
26+
getRouteName(__filename),
27+
getTopHoldersHandler,
28+
schema
29+
);
30+
next();
31+
}

package-lock.json

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"license": "MIT",
2626
"dependencies": {
27-
"@elastic/elasticsearch": "9.0.2",
27+
"@elastic/elasticsearch":"9.0.3",
2828
"@eosrio/node-abieos": "4.0.2-2039717",
2929
"@eosrio/hyperion-plugin-core": "^0.1.0",
3030
"@fastify/autoload": "6.3.1",

0 commit comments

Comments
 (0)