Skip to content

Commit 6050d1d

Browse files
committed
WIP
1 parent d20fd00 commit 6050d1d

File tree

18 files changed

+210
-438
lines changed

18 files changed

+210
-438
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ EXPOSE 3001
1717

1818
ARG INDEXER_MODE_PARAM
1919
ENV INDEXER_MODE=${INDEXER_MODE_PARAM}
20-
CMD ["sh", "-c", "node -r module-alias/register dist/index.js --canonicalTip"]
20+
CMD ["sh", "-c", "node -r module-alias/register dist/index.js $INDEXER_MODE"]

indexer/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@
7575
"create:database": "ts-node -r tsconfig-paths/register src/index.ts --database && yarn migrate:up",
7676
"dev:guards": "ts-node -r tsconfig-paths/register src/index.ts --guards",
7777
"dev:database": "ts-node -r tsconfig-paths/register src/index.ts --database",
78-
"dev:canonical": "ts-node -r tsconfig-paths/register src/index.ts --canonical",
79-
"dev:canonicalTip": "ts-node -r tsconfig-paths/register src/index.ts --canonicalTip",
8078
"dev:backfillPairs": "ts-node -r tsconfig-paths/register src/index.ts --backfillPairs",
8179
"dev:streaming": "ts-node -r tsconfig-paths/register src/index.ts --streaming",
8280
"dev:hot:streaming": "nodemon --exec ts-node -r tsconfig-paths/register src/index.ts --streaming",
83-
"dev:missing": "ts-node -r tsconfig-paths/register src/index.ts --missing",
8481
"dev:graphql": "ts-node -r tsconfig-paths/register src/index.ts --graphql",
8582
"dev:hot:graphql": "nodemon --exec ts-node -r tsconfig-paths/register src/index.ts --graphql",
8683
"graphql:generate-types": "npx graphql-codegen",

indexer/src/index.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@ import { closeDatabase } from './config/database';
1919
import { initializeDatabase } from './config/init';
2020
import { startGraphqlServer } from './kadena-server/server';
2121
import { backfillBalances } from './services/balances';
22-
import { startMissingBlocks } from './services/missing';
2322
import { startStreaming } from './services/streaming';
2423
import { backfillPairEvents } from './services/pair';
2524
import { setupAssociations } from './models/setup-associations';
2625
import { PriceUpdaterService } from '@/services/price/price-updater.service';
27-
import { updateCanonicalInBatches } from '@/services/canonical';
28-
import defineCanonical, { defineCanonicalManually } from '@/services/define-canonical';
2926

3027
/**
3128
* Command-line interface configuration using Commander.
3229
* Defines various operation modes for the indexer through command line flags.
3330
*/
3431
program
3532
.option('-s, --streaming', 'Start streaming blockchain data')
36-
.option('-c, --canonical', 'Update canonical status')
3733
.option('-t, --graphql', 'Start GraphQL server based on kadena schema')
3834
.option('-f, --guards', 'Backfill the guards')
39-
.option('-m, --missing', 'Missing blocks')
4035
.option('-z, --database', 'Init the database')
41-
.option('-o, --canonicalTip', 'Update canonical tip')
4236
.option('-p, --backfillPairs', 'Backfill the pairs');
4337

4438
program.parse(process.argv);
@@ -62,7 +56,7 @@ const options = program.opts();
6256
async function main() {
6357
try {
6458
setupAssociations();
65-
await PriceUpdaterService.getInstance();
59+
PriceUpdaterService.getInstance();
6660

6761
if (options.database) {
6862
await initializeDatabase();
@@ -76,44 +70,9 @@ async function main() {
7670
await backfillBalances();
7771
await closeDatabase();
7872
process.exit(0);
79-
} else if (options.canonical) {
80-
await updateCanonicalInBatches();
81-
await closeDatabase();
82-
process.exit(0);
83-
} else if (options.canonicalTip) {
84-
// for (const chainId of [
85-
// '0',
86-
// '1',
87-
// '2',
88-
// '3',
89-
// '4',
90-
// '5',
91-
// '6',
92-
// '7',
93-
// '8',
94-
// '9',
95-
// '10',
96-
// '11',
97-
// '12',
98-
// '13',
99-
// '14',
100-
// '15',
101-
// '16',
102-
// '17',
103-
// '18',
104-
// '19',
105-
// ]) {
106-
await defineCanonicalManually({ chainId: process.env.CHAIN_ID_CANONICAL ?? '0' });
107-
// console.log(`[INFO] Canonical tip updated for chain ${chainId}`);
108-
// }
109-
process.exit(0);
110-
} else if (options.missing) {
111-
await startMissingBlocks();
112-
process.exit(0);
11373
} else if (options.graphql) {
11474
await startGraphqlServer();
11575
} else if (options.backfillPairs) {
116-
PriceUpdaterService.getInstance();
11776
await backfillPairEvents();
11877
} else {
11978
console.info('[INFO][BIZ][BIZ_FLOW] No specific task requested.');

indexer/src/kadena-server/repository/application/block-repository.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export type FungibleChainAccountOutput = Omit<
4242
>;
4343

4444
export default interface BlockRepository {
45-
getBlockByHash(hash: string): Promise<BlockOutput>;
46-
getBlockParent(hash: string): Promise<BlockOutput | null>;
45+
getBlockByHash(hash: string): Promise<BlockOutput | null>;
4746
getBlocksFromDepth(params: GetBlocksFromDepthParams): Promise<{
4847
pageInfo: PageInfo;
4948
edges: ConnectionEdge<BlockOutput>[];
@@ -82,7 +81,6 @@ export default interface BlockRepository {
8281
): Promise<BlockOutput[]>;
8382

8483
getBlockNParent(depth: number, hash: string): Promise<string | undefined>;
85-
8684
getBlocksWithSameHeight(height: number, chainId: string): Promise<BlockOutput[]>;
8785
getBlocksWithHeightHigherThan(height: number, chainId: string): Promise<BlockOutput[]>;
8886
updateCanonicalStatus(params: UpdateCanonicalStatusParams): Promise<void>;

indexer/src/kadena-server/repository/infra/repository/block-db-repository.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* - Optimized batch retrieval through DataLoader patterns
1515
*/
1616

17-
import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize';
17+
import { Op, QueryTypes } from 'sequelize';
1818
import { rootPgPool, sequelize } from '../../../../config/database';
19-
import BlockModel, { BlockAttributes } from '../../../../models/block';
19+
import BlockModel from '../../../../models/block';
2020
import BlockRepository, {
2121
BlockOutput,
2222
GetBlocksBetweenHeightsParams,
@@ -54,7 +54,7 @@ export default class BlockDbRepository implements BlockRepository {
5454
* @returns Promise resolving to the block data if found
5555
* @throws Error if the block is not found
5656
*/
57-
async getBlockByHash(hash: string) {
57+
async getBlockByHash(hash: string): Promise<BlockOutput | null> {
5858
const block = await BlockModel.findOne({
5959
where: { hash },
6060
});
@@ -66,24 +66,6 @@ export default class BlockDbRepository implements BlockRepository {
6666
return blockValidator.mapFromSequelize(block);
6767
}
6868

69-
/**
70-
* Retrieves the parent block of a given block
71-
*
72-
* This method fetches the parent block of a given block by its hash.
73-
*
74-
* @param parentHash - The hash of the parent block to look up
75-
* @returns Promise resolving to the parent block data if found, or null if not found
76-
*/
77-
async getBlockParent(parentHash: string): Promise<BlockOutput | null> {
78-
const block = await BlockModel.findOne({
79-
where: { hash: parentHash },
80-
});
81-
82-
if (!block) return null;
83-
84-
return blockValidator.mapFromSequelize(block);
85-
}
86-
8769
/**
8870
* Retrieves blocks that have reached a minimum confirmation depth
8971
*

indexer/src/kadena-server/repository/infra/schema-validator/block-schema-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const mapFromSequelize = (blockModel: BlockAttributes): BlockOutput => {
125125
payloadHash: blockModel.payloadHash,
126126
weight: blockModel.weight,
127127
target: blockModel.target,
128-
canonical: blockModel.canonical ?? false, //blockModel.canonical === null ? true : (blockModel.canonical ?? false),
128+
canonical: blockModel.canonical === null ? true : blockModel.canonical ?? false,
129129
neighbors: Object.entries(blockModel.adjacents).map(([chainId, hash]) => ({
130130
chainId,
131131
hash,

indexer/src/kadena-server/resolvers/fields/transfer/block-transfer-resolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ export const blockTransferResolver: TransferResolvers<ResolverContext>['block']
3232
const { blockHash } = schema.parse(parent);
3333
const output = await context.blockRepository.getBlockByHash(blockHash);
3434

35+
if (!output) {
36+
throw new Error('Block transfer not found.');
37+
}
38+
3539
return buildBlockOutput(output);
3640
};

indexer/src/kadena-server/resolvers/node-utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export const getNode = async (context: ResolverContext, id: string) => {
5959
if (type === 'Block') {
6060
// Resolve Block node - only requires the block hash as a parameter
6161
const output = await context.blockRepository.getBlockByHash(params);
62+
if (!output) {
63+
throw new Error('Block not found.');
64+
}
6265
return buildBlockOutput(output);
6366
}
6467

indexer/src/kadena-server/resolvers/query/block-query-resolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ export const blockQueryResolver: QueryResolvers<ResolverContext>['block'] = asyn
3333
const { hash } = args;
3434
const output = await context.blockRepository.getBlockByHash(hash);
3535

36+
if (!output) {
37+
throw new Error('Block not found.');
38+
}
39+
3640
return buildBlockOutput(output);
3741
};

indexer/src/services/canonical.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)