diff --git a/README.md b/README.md index e863fbaeb5..face8f69a7 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Examples: ```sh # Telescope will do the download according to .json file of --config -# Telescope will put proto into location specified by --out +# Telescope will put proto into location specified by --out telescope download --config ./protod.config.json --out ./git-modules ``` @@ -161,7 +161,7 @@ telescope download --config ./protod.config.json --out ./git-modules # Telescope download from target repo according to --git-repo # in format of (i.e. / or //) # can be empty, it will use main as default -# Also --targets is required to specify the targets to download +# Also --targets is required to specify the targets to download # in format like cosmos/auth/v1beta1/auth.proto telescope download --git-repo target-repo --targets target-proto ``` @@ -185,7 +185,7 @@ telescope download --config ./protod.config.json --out ./git-modules --ssh true // // `outDir` is where the output proto will be put // -// `targets` are the target proto to download +// `targets` are the target proto to download // `targets` can be patterns like: // "cosmos/bank/v1beta1/tx.proto", // "cosmos/gov/**/*.proto", @@ -443,6 +443,8 @@ See [LCD Clients](#lcd-clients) for more info. | `rpcClients.scopedIsExclusive` | will allow both scoped bundles and all RPC Clients | `true` | | `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] | | `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` | +| `rpcClients.useConnectComet` | will use connectComet function to get a tendermint client | `undefined` | +| `rpcClients.useQueryClientResolver` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` | | `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` | `rpcClients.clientStyle.useUpdatedClientStyle` | The default value is `false`, which sets the generated client to use the legacy style. Setting it to `true` applies the updated style and activates the remaining options in clientStyle. | `false` | `rpcClients.clientStyle.type` | A string array containing possible values: `all-client`, `sdk-module-client`, and `custom-client`. The value `all-client` generates an all-module-client file. The value `sdk-module-client` generates a client for the module specified by the `sdkModuleClientOption`. The value `custom-client` generates a customized client as specified by `customClientOption` | `undefined` @@ -1107,7 +1109,7 @@ There'll be client files (`all-module-client.ts`, `akash-sdk-module-client.ts`, The `all-module-client.ts` file consolidates all proto imports into one file and exports them as a single client.
All sdk module client files will be identical to the legacy `client.ts` files generated in each module directory, except they will be located in the root directory.
The custom client imports proto files based on `include.patterns`, allowing protos to originate from different modules.
-For example the custom-client.ts will be like: +For example the custom-client.ts will be like: ```ts export const cosmosIbcAminoConverters = { ...cosmosGovV1TxAmino.AminoConverter, diff --git a/__fixtures__/v-next/outputhelperfunc/helper-func-types.ts b/__fixtures__/v-next/outputhelperfunc/helper-func-types.ts index 2297a710d2..3973a7c879 100644 --- a/__fixtures__/v-next/outputhelperfunc/helper-func-types.ts +++ b/__fixtures__/v-next/outputhelperfunc/helper-func-types.ts @@ -43,7 +43,7 @@ export function buildQuery(opts: QueryBuilderOptions) { export interface ITxArgs { signerAddress: string; - message: TMsg; + message: TMsg | TMsg[]; fee: StdFee | 'auto'; memo: string; } @@ -86,7 +86,7 @@ export function buildTx(opts: TxBuilderOptions) { return async ( signerAddress: string, - message: TMsg, + message: TMsg | TMsg[], fee: StdFee | 'auto', memo: string ): Promise => { diff --git a/__fixtures__/v-next/outputhelperfunc/react-query.ts b/__fixtures__/v-next/outputhelperfunc/react-query.ts index a59e281413..88d309a91c 100644 --- a/__fixtures__/v-next/outputhelperfunc/react-query.ts +++ b/__fixtures__/v-next/outputhelperfunc/react-query.ts @@ -175,7 +175,7 @@ export interface ReactMutationParams { builderMutationFn: (clientResolver?: SigningClientResolver) => ( signerAddress: string, - message: TMsg, + message: TMsg | TMsg[], fee: StdFee | 'auto', memo: string ) => Promise, diff --git a/__fixtures__/v-next/outputicjs/helper-func-types.ts b/__fixtures__/v-next/outputicjs/helper-func-types.ts index 5ab176a163..61fcb2a635 100644 --- a/__fixtures__/v-next/outputicjs/helper-func-types.ts +++ b/__fixtures__/v-next/outputicjs/helper-func-types.ts @@ -38,7 +38,7 @@ export function buildQuery(opts: QueryBuilderOptions) { export interface ITxArgs { signerAddress: string; - message: TMsg; + message: TMsg | TMsg[]; fee: StdFee | 'auto'; memo: string; } @@ -78,7 +78,7 @@ export interface TxBuilderOptions { export function buildTx(opts: TxBuilderOptions) { return async ( signerAddress: string, - message: TMsg, + message: TMsg | TMsg[], fee: StdFee | 'auto', memo: string ): Promise => { diff --git a/__fixtures__/v-next/outputicjs/react-query.ts b/__fixtures__/v-next/outputicjs/react-query.ts index 44a38c1c1d..3c74b5a228 100644 --- a/__fixtures__/v-next/outputicjs/react-query.ts +++ b/__fixtures__/v-next/outputicjs/react-query.ts @@ -147,7 +147,7 @@ export interface ReactMutationParams { builderMutationFn: (clientResolver?: SigningClientResolver) => ( signerAddress: string, - message: TMsg, + message: TMsg | TMsg[], fee: StdFee | 'auto', memo: string ) => Promise, diff --git a/__fixtures__/v-next/outputinstantrpc/extern.ts b/__fixtures__/v-next/outputinstantrpc/extern.ts index b56caf20e4..90aec54c2b 100644 --- a/__fixtures__/v-next/outputinstantrpc/extern.ts +++ b/__fixtures__/v-next/outputinstantrpc/extern.ts @@ -5,7 +5,7 @@ */ import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate' -import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; +import { connectComet, Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc"; const _rpcClients: Record = {}; @@ -40,3 +40,15 @@ export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => { return rpc; } + +export const createTm34QueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const tmClient = await Tendermint34Client.connect(rpcEndpoint); + //@ts-ignore + return new QueryClient(tmClient); +} + +export const createConnectCometQueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const cometClient = await connectComet(rpcEndpoint); + //@ts-ignore + return new QueryClient(cometClient); +} diff --git a/__fixtures__/v-next/outputv4/akash/rpc.query.ts b/__fixtures__/v-next/outputv4/akash/rpc.query.ts index a55e40d7f3..24ff47211c 100644 --- a/__fixtures__/v-next/outputv4/akash/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/akash/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { akash: { audit: { diff --git a/__fixtures__/v-next/outputv4/cosmos/cosmos-rpc-client.query.ts b/__fixtures__/v-next/outputv4/cosmos/cosmos-rpc-client.query.ts index bc37ce0db3..b2621c090b 100644 --- a/__fixtures__/v-next/outputv4/cosmos/cosmos-rpc-client.query.ts +++ b/__fixtures__/v-next/outputv4/cosmos/cosmos-rpc-client.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createCosmicRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { bank: { diff --git a/__fixtures__/v-next/outputv4/cosmos/rpc.query.ts b/__fixtures__/v-next/outputv4/cosmos/rpc.query.ts index 7a583ff3e2..cadf3249f4 100644 --- a/__fixtures__/v-next/outputv4/cosmos/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/cosmos/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/__fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts b/__fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts index f1213e3fa7..29e93b11d8 100644 --- a/__fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/__fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts b/__fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts index 84977f0638..689b343b5f 100644 --- a/__fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts +++ b/__fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createEvmosRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { bank: { diff --git a/__fixtures__/v-next/outputv4/evmos/rpc.query.ts b/__fixtures__/v-next/outputv4/evmos/rpc.query.ts index 9169126902..112a5bfca6 100644 --- a/__fixtures__/v-next/outputv4/evmos/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/evmos/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/__fixtures__/v-next/outputv4/extern.ts b/__fixtures__/v-next/outputv4/extern.ts index b56caf20e4..90aec54c2b 100644 --- a/__fixtures__/v-next/outputv4/extern.ts +++ b/__fixtures__/v-next/outputv4/extern.ts @@ -5,7 +5,7 @@ */ import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate' -import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; +import { connectComet, Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc"; const _rpcClients: Record = {}; @@ -40,3 +40,15 @@ export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => { return rpc; } + +export const createTm34QueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const tmClient = await Tendermint34Client.connect(rpcEndpoint); + //@ts-ignore + return new QueryClient(tmClient); +} + +export const createConnectCometQueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const cometClient = await connectComet(rpcEndpoint); + //@ts-ignore + return new QueryClient(cometClient); +} diff --git a/__fixtures__/v-next/outputv4/ibc/rpc.query.ts b/__fixtures__/v-next/outputv4/ibc/rpc.query.ts index 6a632ee738..9e894499a7 100644 --- a/__fixtures__/v-next/outputv4/ibc/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/ibc/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/__fixtures__/v-next/outputv4/osmosis/rpc.query.ts b/__fixtures__/v-next/outputv4/osmosis/rpc.query.ts index 890b421414..8dbccbf742 100644 --- a/__fixtures__/v-next/outputv4/osmosis/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/osmosis/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/__fixtures__/v-next/outputv4/tendermint/rpc.query.ts b/__fixtures__/v-next/outputv4/tendermint/rpc.query.ts index 6785cd44f0..35da3f7e4d 100644 --- a/__fixtures__/v-next/outputv4/tendermint/rpc.query.ts +++ b/__fixtures__/v-next/outputv4/tendermint/rpc.query.ts @@ -1,13 +1,15 @@ import { Rpc } from "../helpers.js"; import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { QueryClient } from "@cosmjs/stargate"; +import { createConnectCometQueryClient } from "../extern.js"; export const createRPCQueryClient = async ({ - rpcEndpoint + rpcEndpoint, + queryClientResolver }: { rpcEndpoint: string | HttpEndpoint; + queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient; }) => { - const tmClient = await connectComet(rpcEndpoint); - const client = new QueryClient(tmClient); + let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint); return { cosmos: { app: { diff --git a/packages/ast/src/clients/rpc/scoped/rpc.ts b/packages/ast/src/clients/rpc/scoped/rpc.ts index 5f4cb97738..ddb9fe72c8 100644 --- a/packages/ast/src/clients/rpc/scoped/rpc.ts +++ b/packages/ast/src/clients/rpc/scoped/rpc.ts @@ -150,7 +150,7 @@ export const createScopedRpcFactory = ( identifier: string, className: string, options?: { - restoreImportExtension?: string; + restoreImportExtension?: string; } ) => { return t.exportNamedDeclaration( @@ -174,6 +174,10 @@ export const createScopedRpcTmFactory = ( identifier: string ) => { const newClientType = context.pluginValue("rpcClients.useConnectComet"); + const useQueryClientResolver = context.pluginValue( + "rpcClients.useQueryClientResolver" + ); + const extensions = context.pluginValue("rpcClients.extensions"); let functionParams; const returnStatement = t.returnStatement( @@ -213,6 +217,13 @@ export const createScopedRpcTmFactory = ( context.addUtil("HttpEndpoint"); context.addUtil("QueryClient"); + const rpcEndpointParam = t.identifier("rpcEndpoint"); + rpcEndpointParam.typeAnnotation = t.tsTypeAnnotation( + t.tsUnionType([ + t.tsStringKeyword(), + t.tsTypeReference(t.identifier("HttpEndpoint")), + ]) + ); functionParams = [ objectPattern( @@ -223,7 +234,14 @@ export const createScopedRpcTmFactory = ( false, true ), - ], + useQueryClientResolver && + t.objectProperty( + t.identifier("queryClientResolver"), + t.identifier("queryClientResolver"), + false, + true + ), + ].filter(Boolean), t.tsTypeAnnotation( t.tsTypeLiteral([ t.tsPropertySignature( @@ -237,30 +255,72 @@ export const createScopedRpcTmFactory = ( ]) ) ), - ]) + useQueryClientResolver && + t.tsPropertySignature( + t.identifier("queryClientResolver"), + t.tsTypeAnnotation( + t.tsFunctionType( + null, + [rpcEndpointParam], + t.tsTypeAnnotation( + t.tsTypeReference( + t.identifier("QueryClient") + ) + ) + ) + ) + ), + ].filter(Boolean)) ) ), ]; - functionStatements = [ - t.variableDeclaration("const", [ - t.variableDeclarator( - t.identifier("tmClient"), - t.awaitExpression(awaitClientCreation) - ), - ]), - ///// - t.variableDeclaration("const", [ - t.variableDeclarator( - t.identifier("client"), - t.newExpression(t.identifier("QueryClient"), [ + if (useQueryClientResolver) { + let createQueryClientName = newClientType ? "createConnectCometQueryClient" : "createTm34QueryClient"; + context.addUtil(createQueryClientName); + + functionStatements = [ + t.variableDeclaration("let", [ + t.variableDeclarator( + t.identifier("client"), + t.conditionalExpression( + t.identifier("queryClientResolver"), + t.callExpression( + t.identifier("queryClientResolver"), + [t.identifier("rpcEndpoint")] + ), + t.awaitExpression( + t.callExpression( + t.identifier(createQueryClientName), + [t.identifier("rpcEndpoint")] + ) + ) + ) + ), + ]), + returnStatement, + ]; + } else { + functionStatements = [ + t.variableDeclaration("const", [ + t.variableDeclarator( t.identifier("tmClient"), - ]) - ), - ]), + t.awaitExpression(awaitClientCreation) + ), + ]), + ///// + t.variableDeclaration("const", [ + t.variableDeclarator( + t.identifier("client"), + t.newExpression(t.identifier("QueryClient"), [ + t.identifier("tmClient"), + ]) + ), + ]), - returnStatement, - ]; + returnStatement, + ]; + } } else { functionParams = rpcFuncArguments(); functionStatements = [returnStatement]; diff --git a/packages/telescope/README.md b/packages/telescope/README.md index e863fbaeb5..face8f69a7 100644 --- a/packages/telescope/README.md +++ b/packages/telescope/README.md @@ -153,7 +153,7 @@ Examples: ```sh # Telescope will do the download according to .json file of --config -# Telescope will put proto into location specified by --out +# Telescope will put proto into location specified by --out telescope download --config ./protod.config.json --out ./git-modules ``` @@ -161,7 +161,7 @@ telescope download --config ./protod.config.json --out ./git-modules # Telescope download from target repo according to --git-repo # in format of (i.e. / or //) # can be empty, it will use main as default -# Also --targets is required to specify the targets to download +# Also --targets is required to specify the targets to download # in format like cosmos/auth/v1beta1/auth.proto telescope download --git-repo target-repo --targets target-proto ``` @@ -185,7 +185,7 @@ telescope download --config ./protod.config.json --out ./git-modules --ssh true // // `outDir` is where the output proto will be put // -// `targets` are the target proto to download +// `targets` are the target proto to download // `targets` can be patterns like: // "cosmos/bank/v1beta1/tx.proto", // "cosmos/gov/**/*.proto", @@ -443,6 +443,8 @@ See [LCD Clients](#lcd-clients) for more info. | `rpcClients.scopedIsExclusive` | will allow both scoped bundles and all RPC Clients | `true` | | `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] | | `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` | +| `rpcClients.useConnectComet` | will use connectComet function to get a tendermint client | `undefined` | +| `rpcClients.useQueryClientResolver` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` | | `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` | `rpcClients.clientStyle.useUpdatedClientStyle` | The default value is `false`, which sets the generated client to use the legacy style. Setting it to `true` applies the updated style and activates the remaining options in clientStyle. | `false` | `rpcClients.clientStyle.type` | A string array containing possible values: `all-client`, `sdk-module-client`, and `custom-client`. The value `all-client` generates an all-module-client file. The value `sdk-module-client` generates a client for the module specified by the `sdkModuleClientOption`. The value `custom-client` generates a customized client as specified by `customClientOption` | `undefined` @@ -1107,7 +1109,7 @@ There'll be client files (`all-module-client.ts`, `akash-sdk-module-client.ts`, The `all-module-client.ts` file consolidates all proto imports into one file and exports them as a single client.
All sdk module client files will be identical to the legacy `client.ts` files generated in each module directory, except they will be located in the root directory.
The custom client imports proto files based on `include.patterns`, allowing protos to originate from different modules.
-For example the custom-client.ts will be like: +For example the custom-client.ts will be like: ```ts export const cosmosIbcAminoConverters = { ...cosmosGovV1TxAmino.AminoConverter, diff --git a/packages/telescope/__tests__/telescope-v4.test.ts b/packages/telescope/__tests__/telescope-v4.test.ts index 6edb5a52ec..515cbd5266 100644 --- a/packages/telescope/__tests__/telescope-v4.test.ts +++ b/packages/telescope/__tests__/telescope-v4.test.ts @@ -160,7 +160,8 @@ const options: TelescopeOptions = { 'ReflectionService', 'ABCIApplication' ], - useConnectComet: true + useConnectComet: true, + useQueryClientResolver: true }, reactQuery: { diff --git a/packages/telescope/src/generators/create-helpers.ts b/packages/telescope/src/generators/create-helpers.ts index 9fa6e54615..047454fe25 100644 --- a/packages/telescope/src/generators/create-helpers.ts +++ b/packages/telescope/src/generators/create-helpers.ts @@ -77,7 +77,7 @@ export const plugin = (builder: TelescopeBuilder) => { write( builder, "extern.ts", - builder.options.rpcClients?.useConnectComet ? externalComet : external + builder.options.rpcClients?.useConnectComet || builder.options.rpcClients?.useQueryClientResolver ? externalComet : external ); } } diff --git a/packages/telescope/src/helpers/external-comet.ts b/packages/telescope/src/helpers/external-comet.ts index 6b74077845..d53e5c31c4 100644 --- a/packages/telescope/src/helpers/external-comet.ts +++ b/packages/telescope/src/helpers/external-comet.ts @@ -1,5 +1,5 @@ export const externalComet = `import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate' -import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; +import { connectComet, Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc"; const _rpcClients: Record = {}; @@ -34,4 +34,16 @@ export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => { return rpc; } + +export const createTm34QueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const tmClient = await Tendermint34Client.connect(rpcEndpoint); + //@ts-ignore + return new QueryClient(tmClient); +} + +export const createConnectCometQueryClient = async (rpcEndpoint: string | HttpEndpoint) => { + const cometClient = await connectComet(rpcEndpoint); + //@ts-ignore + return new QueryClient(cometClient); +} `; \ No newline at end of file diff --git a/packages/telescope/src/utils/index.ts b/packages/telescope/src/utils/index.ts index 4881b873bc..d0857a1418 100644 --- a/packages/telescope/src/utils/index.ts +++ b/packages/telescope/src/utils/index.ts @@ -41,6 +41,8 @@ export const UTILS: { [key: string]: UtilValue } = { fromTimestamp: '__helpers__', fromUtf8: '@cosmjs/encoding', GeneratedType: '@cosmjs/proto-signing', + createTm34QueryClient: '__extern__', + createConnectCometQueryClient: '__extern__', getRpcClient: '__extern__', createRpcClient: '__extern__', getRpcEndpointKey: '__extern__', diff --git a/packages/telescope/types/helpers/external-comet.d.ts b/packages/telescope/types/helpers/external-comet.d.ts index c905734852..2c2c0017e2 100644 --- a/packages/telescope/types/helpers/external-comet.d.ts +++ b/packages/telescope/types/helpers/external-comet.d.ts @@ -1 +1 @@ -export declare const externalComet = "import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate'\nimport { connectComet, HttpEndpoint } from \"@cosmjs/tendermint-rpc\";\n\nconst _rpcClients: Record = {};\n\nexport const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => {\n if (typeof rpcEndpoint === 'string') {\n return rpcEndpoint;\n } else if (!!rpcEndpoint) {\n //@ts-ignore\n return rpcEndpoint.url;\n }\n}\n\nexport const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const key = getRpcEndpointKey(rpcEndpoint);\n if (!key) return;\n if (_rpcClients.hasOwnProperty(key)) {\n return _rpcClients[key];\n }\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(cometClient);\n const rpc = createProtobufRpcClient(client);\n _rpcClients[key] = rpc;\n return rpc;\n}\n\nexport const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(cometClient);\n const rpc = createProtobufRpcClient(client);\n\n return rpc;\n}\n"; +export declare const externalComet = "import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate'\nimport { connectComet, Tendermint34Client, HttpEndpoint } from \"@cosmjs/tendermint-rpc\";\n\nconst _rpcClients: Record = {};\n\nexport const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => {\n if (typeof rpcEndpoint === 'string') {\n return rpcEndpoint;\n } else if (!!rpcEndpoint) {\n //@ts-ignore\n return rpcEndpoint.url;\n }\n}\n\nexport const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const key = getRpcEndpointKey(rpcEndpoint);\n if (!key) return;\n if (_rpcClients.hasOwnProperty(key)) {\n return _rpcClients[key];\n }\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(cometClient);\n const rpc = createProtobufRpcClient(client);\n _rpcClients[key] = rpc;\n return rpc;\n}\n\nexport const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(cometClient);\n const rpc = createProtobufRpcClient(client);\n\n return rpc;\n}\n\nexport const createTm34QueryClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const tmClient = await Tendermint34Client.connect(rpcEndpoint);\n //@ts-ignore\n return new QueryClient(tmClient);\n}\n\nexport const createConnectCometQueryClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n return new QueryClient(cometClient);\n}\n"; diff --git a/packages/types/src/telescope.ts b/packages/types/src/telescope.ts index 39ac2b0888..e3a6a43c02 100644 --- a/packages/types/src/telescope.ts +++ b/packages/types/src/telescope.ts @@ -291,6 +291,7 @@ export interface TelescopeOpts { }; }[]; useConnectComet?: boolean; + useQueryClientResolver?: boolean; }; helperFuncCreators?: { enabled: boolean; diff --git a/packages/types/types/telescope.d.ts b/packages/types/types/telescope.d.ts index 84b9b73d94..2d2c85f2d2 100644 --- a/packages/types/types/telescope.d.ts +++ b/packages/types/types/telescope.d.ts @@ -238,6 +238,7 @@ export interface TelescopeOpts { }; }[]; useConnectComet?: boolean; + useQueryClientResolver?: boolean; }; helperFuncCreators?: { enabled: boolean;