Skip to content

Commit 6fa1acb

Browse files
committed
refactor: removed old graphql code
1 parent 53b8028 commit 6fa1acb

File tree

8 files changed

+18
-1513
lines changed

8 files changed

+18
-1513
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Lint](https://github.com/hack-a-chain-software/indexer-kadena/actions/workflows/lint.yml/badge.svg)](https://github.com/hack-a-chain-software/indexer-kadena/actions/workflows/lint.yml)
55

66
- [`@kadena-indexer/indexer`](indexer/README.md): The indexer package, which is responsible for scanning and storing blocks for Kadena blockchain.
7-
- [`@kadena-indexer/terraform`](terraform/README.md): The Terraform configuration for provisioning the infrastructure required to run the indexer and the node.
87
- [`@kadena-indexer/backfill`](backfill/README.md): The backfill package, which is responsible for backfilling the indexer data.
98

109
## Requirements

indexer/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
"papaparse": "^5.5.2",
4040
"pg": "^8.11.3",
4141
"pg-hstore": "^2.3.4",
42-
"postgraphile": "^4.13.0",
43-
"postgraphile-plugin-connection-filter": "^2.3.0",
4442
"prom-client": "^15.1.0",
4543
"sequelize": "^6.37.0",
4644
"subscriptions-transport-ws": "^0.11.0",

indexer/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* This file orchestrates the initialization and execution of various services based on command line arguments.
44
* The indexer supports multiple operation modes:
55
* - Streaming blockchain data
6-
* - Running GraphQL servers (both Postgraphile and Kadena schema based)
6+
* - Running GraphQL server
77
* - Backfilling guards
88
* - Processing missing blocks
99
* - Database initialization
@@ -44,9 +44,8 @@ const options = program.opts();
4444
* The function handles different operational modes:
4545
* - Database initialization
4646
* - Blockchain data streaming
47-
* - Guard backfilling
48-
* - Missing blocks processing
49-
* - GraphQL server initialization (both Postgraphile and Kadena schema versions)
47+
* - Token Pairs backfilling
48+
* - GraphQL server initialization
5049
*
5150
* TODO: [OPTIMIZATION] Consider implementing a more modular approach for service initialization
5251
* that would allow easier addition of new services without modifying this main function.

indexer/src/models/balance.ts

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import { Model, DataTypes, Optional } from 'sequelize';
1919
import { sequelize } from '../config/database';
2020
import Contract from './contract';
21-
import { gql, makeExtendSchemaPlugin } from 'postgraphile';
2221

2322
/**
2423
* Interface defining the attributes of a Balance.
@@ -219,103 +218,4 @@ Balance.belongsTo(Contract, {
219218
as: 'contract',
220219
});
221220

222-
/**
223-
* GraphQL extension plugin for querying token holders.
224-
*
225-
* This plugin extends the GraphQL schema to provide a specialized endpoint
226-
* for retrieving token holder information for a specific module/contract.
227-
* It includes pagination support for handling large token holder lists
228-
* efficiently and provides calculated percentage ownership statistics.
229-
*
230-
* The resolver calls a database function that optimizes holder calculations
231-
* and pagination for better performance.
232-
*
233-
* The makeExtendSchemaPlugin function is a PostGraphile utility that:
234-
* 1. Allows extending the auto-generated GraphQL schema with custom queries and types
235-
* 2. Provides type safety and integration with PostGraphile's plugin system
236-
* 3. Maintains compatibility with PostGraphile's existing resolvers and connections
237-
* 4. Enables custom database access patterns while preserving GraphQL conventions
238-
*
239-
* In this implementation, it creates:
240-
* - A 'getHolders' query that accepts pagination parameters and a moduleName
241-
* - Custom types for the response structure following Relay connection specifications
242-
* - A resolver that calls a specialized database function for optimal performance
243-
*/
244-
export const getHoldersPlugin = makeExtendSchemaPlugin(build => {
245-
return {
246-
typeDefs: gql`
247-
extend type Query {
248-
getHolders(
249-
moduleName: String!
250-
before: String
251-
after: String
252-
first: Int
253-
last: Int
254-
): HolderResponse
255-
}
256-
257-
type HolderResponse {
258-
edges: [HolderEdge]
259-
pageInfo: PageInfo
260-
totalCount: Int
261-
}
262-
263-
type HolderEdge {
264-
cursor: String
265-
node: HolderNode
266-
}
267-
268-
type HolderNode {
269-
address: String
270-
quantity: Float
271-
percentage: Float
272-
}
273-
`,
274-
resolvers: {
275-
Query: {
276-
getHolders: async (_query, args, context, _resolveInfo) => {
277-
const { moduleName, before, after, first, last } = args;
278-
const { rootPgPool } = context;
279-
280-
// Call the specialized database function with cursor-based pagination parameters
281-
const { rows } = await rootPgPool.query(
282-
`SELECT * FROM get_holders_by_module($1::VARCHAR, $2::VARCHAR, $3::VARCHAR, $4::INT, $5::INT)`,
283-
[moduleName, before, after, first, last],
284-
);
285-
286-
// Transform the database results into Relay-compatible connection format
287-
const holders = rows.map((row: any) => ({
288-
cursor: Buffer.from(row.row_id.toString()).toString('base64'),
289-
node: {
290-
address: row.address,
291-
quantity: row.quantity,
292-
percentage: row.percentage,
293-
},
294-
}));
295-
296-
// Calculate pagination metadata based on results
297-
const hasNextPage = first ? holders.length === first : false;
298-
const hasPreviousPage = last ? holders.length === last : !!after;
299-
300-
const endCursor = hasNextPage ? holders[holders.length - 1].cursor : null;
301-
const startCursor = holders.length > 0 ? holders[0].cursor : null;
302-
const totalCount = holders.length;
303-
304-
// Return a properly structured Relay connection response
305-
return {
306-
edges: holders,
307-
pageInfo: {
308-
endCursor,
309-
hasNextPage,
310-
hasPreviousPage,
311-
startCursor,
312-
},
313-
totalCount,
314-
};
315-
},
316-
},
317-
},
318-
};
319-
});
320-
321221
export default Balance;

indexer/src/models/block.ts

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
* Each block contains metadata about the block itself, references to related blocks,
66
* and cryptographic information needed for blockchain verification.
77
*
8-
* The module also exports a PostGraphile plugin that extends the GraphQL schema
9-
* with custom block queries for API consumers.
108
*/
119

1210
import { Model, DataTypes } from 'sequelize';
1311
import { sequelize } from '../config/database';
14-
import { gql, makeExtendSchemaPlugin } from 'postgraphile';
1512

1613
/**
1714
* Interface defining the attributes of a Block.
@@ -250,121 +247,4 @@ Block.init(
250247
},
251248
);
252249

253-
/**
254-
* PostGraphile plugin that extends the GraphQL schema with custom Block queries.
255-
* This allows API consumers to query blocks by height and perform search operations
256-
* across blocks, transactions, addresses, and tokens.
257-
*
258-
* TODO: [OPTIMIZATION] Consider implementing caching mechanisms for frequently used queries
259-
* to improve API response times.
260-
*/
261-
export const blockQueryPlugin = makeExtendSchemaPlugin(build => {
262-
return {
263-
typeDefs: gql`
264-
extend type Query {
265-
blockByHeight(height: Int!, chainId: Int!): Block
266-
searchAll(searchTerm: String!, limit: Int!, heightFilter: Int): SearchAllResult
267-
}
268-
269-
type SearchAllResult {
270-
blocks: [Block]
271-
transactions: [Transaction]
272-
addresses: [Balance]
273-
tokens: [Contract]
274-
}
275-
`,
276-
resolvers: {
277-
Query: {
278-
/**
279-
* Resolver to find a block by its height and chain ID.
280-
* Uses a direct SQL query for optimal performance.
281-
*/
282-
blockByHeight: async (_query, args, context, resolveInfo) => {
283-
const { height, chainId } = args;
284-
const { rootPgPool } = context;
285-
const { rows } = await rootPgPool.query(
286-
`SELECT * FROM public."Blocks" WHERE height = $1 AND "chainId" = $2`,
287-
[height, chainId],
288-
);
289-
return rows[0];
290-
},
291-
292-
/**
293-
* Resolver for the searchAll query that searches across multiple entities.
294-
* Performs parallel queries for different entity types and combines the results.
295-
*
296-
* TODO: [OPTIMIZATION] This function performs multiple separate queries that could
297-
* potentially be optimized or consolidated for better performance.
298-
*/
299-
searchAll: async (_query, args, context, resolveInfo) => {
300-
const { searchTerm, limit, heightFilter } = args;
301-
const { rootPgPool } = context;
302-
303-
// Query to search for blocks by various hash fields
304-
const blocksQuery = `
305-
SELECT * FROM public."Blocks" WHERE LOWER(hash) = LOWER($1)
306-
UNION ALL
307-
SELECT * FROM public."Blocks" WHERE LOWER(parent) = LOWER($1)
308-
UNION ALL
309-
SELECT * FROM public."Blocks" WHERE LOWER("payloadHash") = LOWER($1)
310-
UNION ALL
311-
SELECT * FROM public."Blocks" WHERE LOWER("transactionsHash") = LOWER($1)
312-
UNION ALL
313-
SELECT * FROM public."Blocks" WHERE LOWER("outputsHash") = LOWER($1)
314-
UNION ALL
315-
SELECT * FROM public."Blocks" WHERE height = $3
316-
LIMIT $2;
317-
`;
318-
319-
// Query to search for transactions by various identifiers
320-
const transactionsQuery = `
321-
SELECT * FROM public."Transactions" WHERE LOWER(requestkey) = LOWER($1)
322-
UNION ALL
323-
SELECT * FROM public."Transactions" WHERE LOWER(txid) = LOWER($1)
324-
UNION ALL
325-
SELECT * FROM public."Transactions" WHERE LOWER(pactid) = LOWER($1)
326-
UNION ALL
327-
SELECT * FROM public."Transactions" WHERE LOWER(sender) = LOWER($1)
328-
LIMIT $2;
329-
`;
330-
331-
// Query to search for accounts/addresses
332-
const addressesQuery = `
333-
SELECT DISTINCT account, module, qualname, network, -1 as "chainId"
334-
FROM public."Balances"
335-
WHERE LOWER(account) = LOWER($1)
336-
ORDER BY account ASC
337-
LIMIT $2
338-
`;
339-
340-
// Query to search for token contracts
341-
const tokensQuery = `
342-
SELECT DISTINCT network, type, module, precision, -1 as "chainId"
343-
FROM public."Contracts"
344-
WHERE (type = 'fungible' OR type = 'poly-fungible')
345-
AND LOWER(module) LIKE LOWER($1)
346-
LIMIT $2
347-
`;
348-
349-
// Execute all queries in parallel for better performance
350-
const [blocks, transactions, addresses, tokens] = await Promise.all([
351-
rootPgPool.query(blocksQuery, [`${searchTerm}`, limit, heightFilter]),
352-
rootPgPool.query(transactionsQuery, [`${searchTerm}`, limit]),
353-
rootPgPool.query(addressesQuery, [`${searchTerm}`, limit]),
354-
rootPgPool.query(tokensQuery, [`%${searchTerm}%`, limit]),
355-
]);
356-
357-
// Combine and return the search results
358-
return {
359-
blocks: blocks.rows,
360-
transactions: transactions.rows,
361-
addresses: addresses.rows,
362-
tokens: tokens.rows,
363-
};
364-
},
365-
},
366-
},
367-
};
368-
});
369-
370250
export default Block;

0 commit comments

Comments
 (0)