Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting types and event parsing for Cosmos SDK 0.50 #271

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"tsconfig-paths": "^3.12.0",
"typescript": "^4.9.5"
"typescript": "^5.5.3"
},
"resolutions": {
"node-fetch": "2.6.7"
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/indexer/api.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('ApiService', () => {

expect(rpcFetchSpy).toHaveBeenCalledTimes(1);
});

it.skip('query block info', async () => {
await prepareApiService(ENDPOINT, CHAINID, tmpPath);

Expand Down
11 changes: 4 additions & 7 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { Uint53 } from '@cosmjs/math';
import { GeneratedType, Registry } from '@cosmjs/proto-signing';
import { Block, defaultRegistryTypes, SearchTxQuery } from '@cosmjs/stargate';
import { CometClient, toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
import {
BlockResponse,
BlockResultsResponse,
Validator,
} from '@cosmjs/tendermint-rpc/build/tendermint37/responses';
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { CosmosProjectNetConfig } from '@subql/common-cosmos';
Expand All @@ -36,7 +31,7 @@ import { SubqueryProject } from '../configure/SubqueryProject';
import * as CosmosUtil from '../utils/cosmos';
import { KyveApi } from '../utils/kyve/kyve';
import { CosmosClientConnection } from './cosmosClient.connection';
import { BlockContent } from './types';
import { BlockContent, BlockResponse, BlockResultsResponse } from './types';

const logger = getLogger('api');

Expand Down Expand Up @@ -257,7 +252,9 @@ export class CosmosSafeClient
};
}

async validators(): Promise<readonly Validator[]> {
async validators(): Promise<
Awaited<ReturnType<CometClient['validators']>>['validators']
> {
return (
await this.forceGetCometClient().validators({
height: this.height,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/indexer/cosmosClient.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const logger = getLogger('CosmosClientConnection');
/**
* Auto-detects the version of the backend and uses a suitable client.
*/
export async function connectComet(
async function connectComet(
client: WebsocketClient | HttpClient,
): Promise<CometClient> {
// Tendermint/CometBFT 0.34/0.37/0.38 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
Expand Down
18 changes: 16 additions & 2 deletions packages/node/src/indexer/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import type {
tendermint34,
tendermint37,
comet38,
} from '@cosmjs/tendermint-rpc';
import {
CosmosBlock,
CosmosEvent,
CosmosTransaction,
CosmosMessage,
} from '@subql/types-cosmos';

export type BlockResponse =
| tendermint34.BlockResponse
| tendermint37.BlockResponse
| comet38.BlockResponse;
export type BlockResultsResponse =
| tendermint34.BlockResultsResponse
| tendermint37.BlockResultsResponse
| comet38.BlockResultsResponse;

export interface BlockContent {
block: CosmosBlock;
transactions: CosmosTransaction[];
messages: CosmosMessage[];
events: CosmosEvent[];
beginBlockEvents: CosmosEvent[];
endBlockEvents: CosmosEvent[];
beginBlockEvents?: CosmosEvent[];
endBlockEvents?: CosmosEvent[];
}

export type BestBlocks = Record<number, string>;
Loading
Loading