diff --git a/package.json b/package.json index 9be824799..0273b6715 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/node/src/indexer/api.service.test.ts b/packages/node/src/indexer/api.service.test.ts index 844cf2175..4f484e12d 100644 --- a/packages/node/src/indexer/api.service.test.ts +++ b/packages/node/src/indexer/api.service.test.ts @@ -107,6 +107,7 @@ describe('ApiService', () => { expect(rpcFetchSpy).toHaveBeenCalledTimes(1); }); + it.skip('query block info', async () => { await prepareApiService(ENDPOINT, CHAINID, tmpPath); diff --git a/packages/node/src/indexer/api.service.ts b/packages/node/src/indexer/api.service.ts index c51077fb9..10b5bc38a 100644 --- a/packages/node/src/indexer/api.service.ts +++ b/packages/node/src/indexer/api.service.ts @@ -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'; @@ -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'); @@ -257,7 +252,9 @@ export class CosmosSafeClient }; } - async validators(): Promise { + async validators(): Promise< + Awaited>['validators'] + > { return ( await this.forceGetCometClient().validators({ height: this.height, diff --git a/packages/node/src/indexer/cosmosClient.connection.ts b/packages/node/src/indexer/cosmosClient.connection.ts index eca27288a..a2c6d4af2 100644 --- a/packages/node/src/indexer/cosmosClient.connection.ts +++ b/packages/node/src/indexer/cosmosClient.connection.ts @@ -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 { // Tendermint/CometBFT 0.34/0.37/0.38 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉 diff --git a/packages/node/src/indexer/types.ts b/packages/node/src/indexer/types.ts index 372b0a21e..496eb3233 100644 --- a/packages/node/src/indexer/types.ts +++ b/packages/node/src/indexer/types.ts @@ -1,6 +1,11 @@ // 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, @@ -8,13 +13,22 @@ import { 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; diff --git a/packages/node/src/utils/cosmos.spec.ts b/packages/node/src/utils/cosmos.spec.ts index 14993f494..fefb01bff 100644 --- a/packages/node/src/utils/cosmos.spec.ts +++ b/packages/node/src/utils/cosmos.spec.ts @@ -1,14 +1,9 @@ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -import { - GeneratedType, - Registry, - decodeTxRaw, - DecodedTxRaw, -} from '@cosmjs/proto-signing'; +import { GeneratedType, Registry, DecodedTxRaw } from '@cosmjs/proto-signing'; import { defaultRegistryTypes } from '@cosmjs/stargate'; -import { Tendermint37Client } from '@cosmjs/tendermint-rpc'; +import { connectComet, CometClient } from '@cosmjs/tendermint-rpc'; import { CosmosMessageFilter, CosmosBlock, @@ -23,10 +18,10 @@ import { MsgStoreCode, MsgUpdateAdmin, } from 'cosmjs-types/cosmwasm/wasm/v1/tx'; -import { isLong, fromInt } from 'long'; +import { fromInt } from 'long'; import { CosmosClient } from '../indexer/api.service'; -import { HttpClient } from '../indexer/rpc-clients'; -import { decodeMsg, filterMessageData, wrapEvent } from './cosmos'; +import { BlockContent } from '../indexer/types'; +import { fetchBlocksBatches, filterMessageData, wrapEvent } from './cosmos'; const ENDPOINT = 'https://rpc.mainnet.archway.io'; @@ -84,12 +79,12 @@ const TEST_MESSAGE_FILTER_FALSE_2: CosmosMessageFilter = { jest.setTimeout(200000); describe('CosmosUtils', () => { let api: CosmosClient; - let decodedTx: DecodedTxRaw; + // let decodedTx: DecodedTxRaw; let msg: CosmosMessage; + let block: BlockContent; beforeAll(async () => { - const client = new HttpClient(ENDPOINT); - const tendermint = await Tendermint37Client.create(client); + const tendermint = await connectComet(ENDPOINT); const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [ ['/cosmwasm.wasm.v1.MsgClearAdmin', MsgClearAdmin], ['/cosmwasm.wasm.v1.MsgExecuteContract', MsgExecuteContract], @@ -101,147 +96,165 @@ describe('CosmosUtils', () => { const registry = new Registry([...defaultRegistryTypes, ...wasmTypes]); api = new CosmosClient(tendermint, registry); - const block = await api.getBlock(TEST_BLOCKNUMBER); - const tx = block.txs[1]; - decodedTx = decodeTxRaw(tx); - msg = { - idx: 0, - block: {} as CosmosBlock, - tx: { - tx: { - code: 0, - }, - } as CosmosTransaction, - msg: { - typeUrl: decodedTx.body.messages[0].typeUrl, - get decodedMsg() { - return decodeMsg(decodedTx.body.messages[0], registry); - }, - }, - }; - }); - it('filter message data for true', () => { - const result = filterMessageData(msg, TEST_MESSAGE_FILTER_TRUE); - expect(result).toEqual(true); + const [firstBlock] = await fetchBlocksBatches(api, [TEST_BLOCKNUMBER]); + block = firstBlock.block; + msg = block.messages[2]; }); - it('filter message data for false', () => { - const result = filterMessageData(msg, TEST_MESSAGE_FILTER_FALSE); - expect(result).toEqual(false); + afterAll(() => { + api.disconnect(); }); - it('filter nested message data for true', () => { - const result = filterMessageData(msg, TEST_NESTED_MESSAGE_FILTER_TRUE); - expect(result).toEqual(true); - }); + describe('Parsing block data', () => { + it('Correctly wraps events', () => { + // First event of the second message + const event = block.events[17]; + expect(event.block).toBeDefined(); + expect(event.tx).toBeDefined(); + expect(event.idx).toEqual(17); - it('filter nested message data for false', () => { - const result = filterMessageData(msg, TEST_NESTED_MESSAGE_FILTER_FALSE); - expect(result).toEqual(false); - }); + expect(event.msg).toBeDefined(); + expect(event.msg.msg.typeUrl).toEqual( + '/cosmwasm.wasm.v1.MsgExecuteContract', + ); - it('filter nested message data for invalid path', () => { - const result = filterMessageData( - msg, - TEST_NESTED_MESSAGE_FILTER_INVALID_PATH, - ); - expect(result).toEqual(false); - }); + expect(event.msg.tx.hash).toEqual(event.tx.hash); - it('does not wrap events of failed transaction', async () => { - const blockInfo = await api.blockResults(TEST_FAILTX_BLOCKNUMBER); - const failedTx = blockInfo.results[1]; - const tx: CosmosTransaction = { - idx: 0, - block: {} as CosmosBlock, - tx: failedTx, - hash: '', - decodedTx: {} as DecodedTxRaw, - }; - const events = wrapEvent({} as CosmosBlock, [tx], api.registry, 0); - expect(events.length).toEqual(0); - }); + expect(event.event).toBeDefined(); + expect(event.event.type).toEqual( + 'wasm-astrovault-cashback_minter-receive_swap_data', + ); + expect(event.event.attributes.length).toEqual(3); - it('does not lazy decode failed message filters', () => { - const spy = jest.spyOn(msg.msg, 'decodedMsg', 'get'); - const result = filterMessageData(msg, TEST_MESSAGE_FILTER_FALSE_2); - expect(spy).not.toHaveBeenCalled(); + expect(event.log.events.length).toEqual(12); + }); }); - it('lazy decode passed message filters', () => { - const spy = jest.spyOn(msg.msg, 'decodedMsg', 'get'); - const result = filterMessageData(msg, TEST_MESSAGE_FILTER_TRUE); - expect(spy).toHaveBeenCalled(); - }); + describe('filtering', () => { + it('filter message data for true', () => { + const result = filterMessageData(msg, TEST_MESSAGE_FILTER_TRUE); + expect(result).toEqual(true); + }); - it('can filter long type decoded msg for true', () => { - const msg: CosmosMessage = { - tx: null, - msg: { - typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - decodedMsg: { - codeId: fromInt(4), + it('filter message data for false', () => { + const result = filterMessageData(msg, TEST_MESSAGE_FILTER_FALSE); + expect(result).toEqual(false); + }); + + it('filter nested message data for true', () => { + const result = filterMessageData(msg, TEST_NESTED_MESSAGE_FILTER_TRUE); + expect(result).toEqual(true); + }); + + it('filter nested message data for false', () => { + const result = filterMessageData(msg, TEST_NESTED_MESSAGE_FILTER_FALSE); + expect(result).toEqual(false); + }); + + it('filter nested message data for invalid path', () => { + const result = filterMessageData( + msg, + TEST_NESTED_MESSAGE_FILTER_INVALID_PATH, + ); + expect(result).toEqual(false); + }); + + it('does not wrap events of failed transaction', async () => { + const blockInfo = await api.blockResults(TEST_FAILTX_BLOCKNUMBER); + const failedTx = blockInfo.results[1]; + const tx: CosmosTransaction = { + idx: 0, + block: {} as CosmosBlock, + tx: failedTx, + hash: '', + decodedTx: {} as DecodedTxRaw, + }; + const events = wrapEvent({} as CosmosBlock, [tx], api.registry, 0); + expect(events.length).toEqual(0); + }); + + // These lazy decode methods don't work as the getter is replaced with the result once called + it.skip('does not lazy decode failed message filters', () => { + const spy = jest.spyOn(msg.msg, 'decodedMsg', 'get'); + filterMessageData(msg, TEST_MESSAGE_FILTER_FALSE_2); + expect(spy).not.toHaveBeenCalled(); + }); + + it.skip('lazy decode passed message filters', () => { + const spy = jest.spyOn(msg.msg, 'decodedMsg', 'get'); + filterMessageData(msg, TEST_MESSAGE_FILTER_TRUE); + expect(spy).toHaveBeenCalled(); + }); + + it('can filter long type decoded msg for true', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, }, - }, - } as unknown as CosmosMessage; + } as unknown as CosmosMessage; - const filter: CosmosMessageFilter = { - type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - values: { - codeId: '4', - }, - includeFailedTx: true, - }; + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: '4', + }, + includeFailedTx: true, + }; - const result = filterMessageData(msg, filter); - expect(result).toEqual(true); - }); + const result = filterMessageData(msg, filter); + expect(result).toEqual(true); + }); - it('can filter long type decoded msg for number filter', () => { - const msg: CosmosMessage = { - tx: null, - msg: { - typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - decodedMsg: { - codeId: fromInt(4), + it('can filter long type decoded msg for number filter', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, }, - }, - } as unknown as CosmosMessage; + } as unknown as CosmosMessage; - const filter: CosmosMessageFilter = { - type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - values: { - codeId: 4 as unknown as string, - }, - includeFailedTx: true, - }; + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: 4 as unknown as string, + }, + includeFailedTx: true, + }; - const result = filterMessageData(msg, filter); - expect(result).toEqual(true); - }); + const result = filterMessageData(msg, filter); + expect(result).toEqual(true); + }); - it('can filter long type decoded msg for false', () => { - const msg: CosmosMessage = { - tx: null, - msg: { - typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - decodedMsg: { - codeId: fromInt(4), + it('can filter long type decoded msg for false', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, }, - }, - } as unknown as CosmosMessage; + } as unknown as CosmosMessage; - const filter: CosmosMessageFilter = { - type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - values: { - codeId: '5', - }, - includeFailedTx: true, - }; + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: '5', + }, + includeFailedTx: true, + }; - const result = filterMessageData(msg, filter); - expect(result).toEqual(false); + const result = filterMessageData(msg, filter); + expect(result).toEqual(false); + }); }); describe('filterMessageData function', () => { @@ -329,8 +342,62 @@ describe('CosmosUtils', () => { }); }); }); +}); - afterEach(() => { - api.disconnect(); +describe('Cosmos 0.50 support', () => { + let api: CosmosClient; + let client: CometClient; + let block: BlockContent; + + beforeAll(async () => { + client = await connectComet('https://rpc.neutron.quokkastake.io'); + const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [ + ['/cosmwasm.wasm.v1.MsgClearAdmin', MsgClearAdmin], + ['/cosmwasm.wasm.v1.MsgExecuteContract', MsgExecuteContract], + ['/cosmwasm.wasm.v1.MsgMigrateContract', MsgMigrateContract], + ['/cosmwasm.wasm.v1.MsgStoreCode', MsgStoreCode], + ['/cosmwasm.wasm.v1.MsgInstantiateContract', MsgInstantiateContract], + ['/cosmwasm.wasm.v1.MsgUpdateAdmin', MsgUpdateAdmin], + ]; + + const registry = new Registry([...defaultRegistryTypes, ...wasmTypes]); + api = new CosmosClient(client, registry); + + const [firstBlock] = await fetchBlocksBatches(api, [12_495_419]); // https://www.mintscan.io/neutron/block/12495419 + block = firstBlock.block; + }); + + // This test is just to ensure + it('Is a cosmos 0.50 network', async () => { + const status = await client.status(); + + expect(status.nodeInfo.version).toMatch('0.38.'); + }); + + // TODO requires these changes https://github.com/cosmos/cosmjs/compare/main...bryanchriswhite:cosmjs:main + it('correctly has finalized block events instead of being/end block events', () => { + // Its not yet defined if cosmjs will split finalizedBlockEvents to these to fields or define finalizedBlockEvents + expect(block.beginBlockEvents).toBeDefined(); + expect(block.endBlockEvents).toBeDefined(); + }); + + it('correctly parses events', () => { + const event = block.events[0]; + expect(event.block).toBeDefined(); + expect(event.tx).toBeDefined(); + expect(event.idx).toEqual(0); + + expect(event.msg).toBeDefined(); + expect(event.msg.msg.typeUrl).toEqual( + '/ibc.core.client.v1.MsgUpdateClient', + ); + + expect(event.msg.tx.hash).toEqual(event.tx.hash); + + expect(event.event).toBeDefined(); + expect(event.event.type).toEqual('message'); + expect(event.event.attributes.length).toEqual(3); + + expect(event.log.events.length).toEqual(0); }); }); diff --git a/packages/node/src/utils/cosmos.ts b/packages/node/src/utils/cosmos.ts index 8112e9b18..5989adc29 100644 --- a/packages/node/src/utils/cosmos.ts +++ b/packages/node/src/utils/cosmos.ts @@ -9,13 +9,6 @@ import { DecodeObject, decodeTxRaw, Registry } from '@cosmjs/proto-signing'; import { fromTendermintEvent } from '@cosmjs/stargate'; import { Log, parseRawLog } from '@cosmjs/stargate/build/logs'; import { toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc'; -import { - BlockResponse, - BlockResultsResponse, - TxData, - Event, - Header as CosmosHeader, -} from '@cosmjs/tendermint-rpc/build/tendermint37'; import { IBlock, getLogger, @@ -23,6 +16,9 @@ import { filterBlockTimestamp, } from '@subql/node-core'; import { + TxData, + TxEvent, + Header as CosmosHeader, CosmosEventFilter, CosmosMessageFilter, CosmosBlock, @@ -36,7 +32,11 @@ import { isObjectLike } from 'lodash'; import { isLong } from 'long'; import { SubqlProjectBlockFilter } from '../configure/SubqueryProject'; import { CosmosClient } from '../indexer/api.service'; -import { BlockContent } from '../indexer/types'; +import { + BlockContent, + BlockResponse, + BlockResultsResponse, +} from '../indexer/types'; const logger = getLogger('fetch'); @@ -311,7 +311,7 @@ function wrapMsg( export function wrapBlockBeginAndEndEvents( block: CosmosBlock, - events: Event[], + events: TxEvent[], idxOffset: number, ): CosmosEvent[] { return events.map( @@ -327,6 +327,13 @@ export function wrapBlockBeginAndEndEvents( ); } +// With tendermint34 the Attrbutes type key and value were Uint8Arrays +function attrToString(value: string | Uint8Array): string { + return typeof value === 'string' + ? value + : Buffer.from(value).toString('utf8'); +} + export function wrapEvent( block: CosmosBlock, txs: CosmosTransaction[], @@ -335,35 +342,74 @@ export function wrapEvent( ): CosmosEvent[] { const events: CosmosEvent[] = []; for (const tx of txs) { - let logs: Log[]; - try { - logs = parseRawLog(tx.tx.log) as Log[]; - } catch (e) { - //parsing fails if transaction had failed. - logger.debug('Failed to parse raw log, most likely a failed transaction'); - continue; - } - for (const log of logs) { - let msg: CosmosMessage; + const appendEvent = (msg: CosmosMessage, event: TxEvent, log: Log) => { + events.push({ + idx: idxOffset++, + block, + tx, + msg, + event, + log, + }); + }; + + /** + * Is there a better way of doing this? + * 34,37 also provide tx.tx.events, but logs don't seem to be recoverable that way. + * Are logs even of use? They are just a subset of event attributes */ + if (tx.tx?.log) { + // Tendermint34, Tendermint37 + let logs: Log[]; try { - msg = wrapCosmosMsg(block, tx, log.msg_index, registry); + logs = parseRawLog(tx.tx.log) as Log[]; } catch (e) { - // Example where this can happen https://sei.explorers.guru/transaction/8D4CA68E917E15652E10CB960DE604AEEB1B183D6E94A85E9CD98403F15550B7 - logger.warn( - `Unable to find message for event. tx=${tx.hash} messageIdx=${log.msg_index}`, + //parsing fails if transaction had failed. + logger.debug( + 'Failed to parse raw log, most likely a failed transaction', ); + continue; + } + for (const log of logs) { + let msg: CosmosMessage; + try { + msg = wrapCosmosMsg(block, tx, log.msg_index, registry); + } catch (e) { + // Example where this can happen https://sei.explorers.guru/transaction/8D4CA68E917E15652E10CB960DE604AEEB1B183D6E94A85E9CD98403F15550B7 + logger.warn( + `Unable to find message for event. tx=${tx.hash} messageIdx=${log.msg_index}`, + ); + continue; + } + for (let i = 0; i < log.events.length; i++) { + appendEvent(msg, log.events[i], log); + } } - for (let i = 0; i < log.events.length; i++) { - const event: CosmosEvent = { - idx: idxOffset++, - msg, - tx, - block, - log, - event: log.events[i], - }; - events.push(event); + } else if (tx.tx?.events) { + // Comet38 + for (const txEvent of tx.tx.events) { + let msg: CosmosMessage; + try { + const eventMsgIndex = txEvent.attributes.find( + (attr) => attrToString(attr.key) === 'msg_index', + )?.value; + + // Event doesn't have a message + if (eventMsgIndex === undefined) { + continue; + } + + const msgNumber = parseInt(attrToString(eventMsgIndex), 10); + msg = wrapCosmosMsg(block, tx, msgNumber, registry); + } catch (e) { + logger.warn(`Unable to find message for event. tx=${tx.hash}`); + continue; + } + + // TODO does a log still exist in Comet38? + appendEvent(msg, txEvent, { events: [], log: '', msg_index: -1 }); } + } else { + // For some tests that have invalid data } } diff --git a/packages/node/src/utils/kyve/kyve.spec.ts b/packages/node/src/utils/kyve/kyve.spec.ts index 08b6d8601..28aefd41f 100644 --- a/packages/node/src/utils/kyve/kyve.spec.ts +++ b/packages/node/src/utils/kyve/kyve.spec.ts @@ -9,11 +9,7 @@ import { gzipSync } from 'zlib'; import { JsonRpcSuccessResponse } from '@cosmjs/json-rpc'; import { GeneratedType, Registry } from '@cosmjs/proto-signing'; import { defaultRegistryTypes } from '@cosmjs/stargate'; -import { Tendermint37Client } from '@cosmjs/tendermint-rpc'; -import { - BlockResponse, - BlockResultsResponse, -} from '@cosmjs/tendermint-rpc/build/tendermint37/responses'; +import { connectComet, CometClient } from '@cosmjs/tendermint-rpc'; import KyveSDK from '@kyvejs/sdk'; import { makeTempDir } from '@subql/common'; import { delay } from '@subql/node-core'; @@ -28,7 +24,7 @@ import { } from 'cosmjs-types/cosmwasm/wasm/v1/tx'; import { isEqual } from 'lodash'; import rimraf from 'rimraf'; -import { HttpClient } from '../../indexer/rpc-clients'; +import { BlockResponse, BlockResultsResponse } from '../../indexer/types'; import { LazyBlockContent } from '../cosmos'; import { KyveApi } from './kyve'; import { BundleDetails } from './kyveTypes'; @@ -55,7 +51,7 @@ const KYVE_CHAINID = 'kyve-1'; jest.setTimeout(100000); describe('KyveApi', () => { let kyveApi: KyveApi; - let tendermint: Tendermint37Client; + let tendermint: CometClient; let registry: Registry; let tmpPath: string; @@ -81,8 +77,7 @@ describe('KyveApi', () => { tmpPath, 300, ); - const client = new HttpClient('https://rpc.mainnet.archway.io:443'); - tendermint = await Tendermint37Client.create(client); + tendermint = await connectComet('https://rpc.mainnet.archway.io:443'); }); beforeEach(async () => { diff --git a/packages/node/src/utils/kyve/kyve.ts b/packages/node/src/utils/kyve/kyve.ts index 702ab81a5..8d8eee1e7 100644 --- a/packages/node/src/utils/kyve/kyve.ts +++ b/packages/node/src/utils/kyve/kyve.ts @@ -9,18 +9,18 @@ import * as zlib from 'zlib'; import { JsonRpcSuccessResponse } from '@cosmjs/json-rpc'; import { Registry } from '@cosmjs/proto-signing'; import { logs } from '@cosmjs/stargate'; -import { - BlockResponse, - BlockResultsResponse, - TxData, -} from '@cosmjs/tendermint-rpc/build/tendermint37'; import { Responses } from '@cosmjs/tendermint-rpc/build/tendermint37/adaptor'; // adaptor is not exported import KyveSDK, { KyveLCDClientType } from '@kyvejs/sdk'; import { SupportedChains } from '@kyvejs/sdk/src/constants'; // Currently these types are not exported import { QueryPoolsResponse } from '@kyvejs/types/lcd/kyve/query/v1beta1/pools'; import { delay, getLogger, IBlock, timeout } from '@subql/node-core'; +import { TxData } from '@subql/types-cosmos'; import axios, { AxiosResponse } from 'axios'; -import { BlockContent } from '../../indexer/types'; +import { + BlockContent, + BlockResponse, + BlockResultsResponse, +} from '../../indexer/types'; import { formatBlockUtil, LazyBlockContent } from '../cosmos'; import { isTmpDir } from '../project'; import { BundleDetails } from './kyveTypes'; diff --git a/packages/types/src/interfaces.ts b/packages/types/src/interfaces.ts index 7ea6c803a..514cc0338 100644 --- a/packages/types/src/interfaces.ts +++ b/packages/types/src/interfaces.ts @@ -3,11 +3,17 @@ import {CosmWasmClient} from '@cosmjs/cosmwasm-stargate'; import {DecodedTxRaw} from '@cosmjs/proto-signing'; -import {Event} from '@cosmjs/stargate'; import {Log} from '@cosmjs/stargate/build/logs'; -import {Validator, TxData, Block, BlockId, Header} from '@cosmjs/tendermint-rpc/build/tendermint37'; +import type {tendermint34, tendermint37, comet38} from '@cosmjs/tendermint-rpc'; import Long from 'long'; +export type Block = tendermint34.Block | tendermint37.Block | comet38.Block; +export type BlockId = tendermint34.BlockId | tendermint37.BlockId | comet38.BlockId; +export type Validator = tendermint34.Validator | tendermint37.Validator | comet38.Validator; +export type TxData = tendermint34.TxData | tendermint37.TxData | comet38.TxData; +export type TxEvent = tendermint34.Event | tendermint37.Event | comet38.Event; +export type Header = tendermint34.Header | tendermint37.Header | comet38.Header; + export interface CosmWasmSafeClient extends CosmWasmClient { validators: () => Promise; } @@ -46,7 +52,7 @@ export interface CosmosEvent { tx: CosmosTransaction; msg: CosmosMessage; log: Log; - event: Event; + event: TxEvent; } export type DynamicDatasourceCreator = (name: string, args: Record) => Promise; diff --git a/yarn.lock b/yarn.lock index 1f8bd807b..c8569da43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16998,7 +16998,7 @@ __metadata: ts-loader: ^9.2.6 ts-node: ^10.4.0 tsconfig-paths: ^3.12.0 - typescript: ^4.9.5 + typescript: ^5.5.3 languageName: unknown linkType: soft @@ -17647,23 +17647,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^4.9.5": - version: 4.9.5 - resolution: "typescript@npm:4.9.5" +"typescript@npm:^5.5.3": + version: 5.5.3 + resolution: "typescript@npm:5.5.3" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db + checksum: 4b4f14313484d5c86064d04ba892544801fa551f5cf72719b540b498056fec7fc192d0bbdb2ba1448e759b1548769956da9e43e7c16781e8d8856787b0575004 languageName: node linkType: hard -"typescript@patch:typescript@^4.9.5#~builtin": - version: 4.9.5 - resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=493e53" +"typescript@patch:typescript@^5.5.3#~builtin": + version: 5.5.3 + resolution: "typescript@patch:typescript@npm%3A5.5.3#~builtin::version=5.5.3&hash=493e53" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 2eee5c37cad4390385db5db5a8e81470e42e8f1401b0358d7390095d6f681b410f2c4a0c496c6ff9ebd775423c7785cdace7bcdad76c7bee283df3d9718c0f20 + checksum: 6853be4607706cc1ad2f16047cf1cd72d39f79acd5f9716e1d23bc0e462c7f59be7458fe58a21665e7657a05433d7ab8419d093a5a4bd5f3a33f879b35d2769b languageName: node linkType: hard