Skip to content

Commit

Permalink
Add getChainTopUserTransactions.graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin authored and gregnazario committed Oct 13, 2023
1 parent 590fce0 commit 6ccc28e
Show file tree
Hide file tree
Showing 8 changed files with 3,362 additions and 3,148 deletions.
27 changes: 26 additions & 1 deletion src/api/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
import {
getBlockByHeight,
getBlockByVersion,
getChainTopUserTransactions,
getLedgerInfo,
getTableItem,
queryIndexer,
view,
} from "../internal/general";
import { Block, GraphqlQuery, LedgerInfo, LedgerVersion, MoveValue, TableItemRequest, ViewRequest } from "../types";
import {
Block,
GetChainTopUserTransactionsResponse,
GraphqlQuery,
LedgerInfo,
LedgerVersion,
MoveValue,
TableItemRequest,
ViewRequest,
} from "../types";
import { AptosConfig } from "./aptos_config";

/**
Expand Down Expand Up @@ -125,6 +135,21 @@ export class General {
return data[0];
}

/**
* Queries top user transactions
*
* @param args.limit
* @returns GetChainTopUserTransactionsResponse
*/
async getChainTopUserTransactions(args: { limit: number }): Promise<GetChainTopUserTransactionsResponse> {
const data = getChainTopUserTransactions({
aptosConfig: this.config,
...args,
});

return data;
}

/**
* A generic function for retrieving data from Aptos Indexer.
* For more detailed queries specification see
Expand Down
32 changes: 31 additions & 1 deletion src/internal/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@

import { AptosConfig } from "../api/aptos_config";
import { getAptosFullNode, postAptosFullNode, postAptosIndexer } from "../client";
import { Block, GraphqlQuery, LedgerInfo, LedgerVersion, MoveValue, TableItemRequest, ViewRequest } from "../types";
import {
Block,
GetChainTopUserTransactionsResponse,
GraphqlQuery,
LedgerInfo,
LedgerVersion,
MoveValue,
TableItemRequest,
ViewRequest,
} from "../types";
import { GetChainTopUserTransactionsQuery } from "../types/generated/operations";
import { GetChainTopUserTransactions } from "../types/generated/queries";

export async function getLedgerInfo(args: { aptosConfig: AptosConfig }): Promise<LedgerInfo> {
const { aptosConfig } = args;
Expand Down Expand Up @@ -85,6 +96,25 @@ export async function view(args: {
return data;
}

export async function getChainTopUserTransactions(args: {
aptosConfig: AptosConfig;
limit: number;
}): Promise<GetChainTopUserTransactionsResponse> {
const { aptosConfig, limit } = args;
const graphqlQuery = {
query: GetChainTopUserTransactions,
variables: { limit },
};

const data = await queryIndexer<GetChainTopUserTransactionsQuery>({
aptosConfig,
query: graphqlQuery,
originMethod: "getChainTopUserTransactions",
});

return data.user_transactions;
}

export async function queryIndexer<T>(args: {
aptosConfig: AptosConfig;
query: GraphqlQuery;
Expand Down
5 changes: 5 additions & 0 deletions src/internal/queries/getChainTopUserTransactions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query getChainTopUserTransactions($limit: Int) {
user_transactions(limit: $limit, order_by: { version: desc }) {
version
}
}
Loading

0 comments on commit 6ccc28e

Please sign in to comment.