Skip to content

Commit

Permalink
add useQueryClientResolver to rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jan 16, 2025
1 parent 9d5a31e commit cd1ab64
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 67 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ 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
```

```sh
# Telescope download from target repo according to --git-repo
# in format of (i.e. <owner>/<repository> or <owner>/<repository>/<branch>)
# <branch> 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
```
Expand All @@ -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",
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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.<br>
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. <br>
The custom client imports proto files based on `include.patterns`, allowing protos to originate from different modules.<br>
For example the custom-client.ts will be like:
For example the custom-client.ts will be like:
```ts
export const cosmosIbcAminoConverters = {
...cosmosGovV1TxAmino.AminoConverter,
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputhelperfunc/helper-func-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function buildQuery<TReq, TRes>(opts: QueryBuilderOptions<TReq, TRes>) {

export interface ITxArgs<TMsg> {
signerAddress: string;
message: TMsg;
message: TMsg | TMsg[];
fee: StdFee | 'auto';
memo: string;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export function buildTx<TMsg>(opts: TxBuilderOptions) {

return async (
signerAddress: string,
message: TMsg,
message: TMsg | TMsg[],
fee: StdFee | 'auto',
memo: string
): Promise<DeliverTxResponse> => {
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputhelperfunc/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface ReactMutationParams<TData, TError, TVariables, TContext = unkno
export interface UseMutationBuilderOptions<TMsg> {
builderMutationFn: (clientResolver?: SigningClientResolver) => (
signerAddress: string,
message: TMsg,
message: TMsg | TMsg[],
fee: StdFee | 'auto',
memo: string
) => Promise<DeliverTxResponse>,
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputicjs/helper-func-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function buildQuery<TReq, TRes>(opts: QueryBuilderOptions<TReq, TRes>) {

export interface ITxArgs<TMsg> {
signerAddress: string;
message: TMsg;
message: TMsg | TMsg[];
fee: StdFee | 'auto';
memo: string;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ export interface TxBuilderOptions {
export function buildTx<TMsg>(opts: TxBuilderOptions) {
return async (
signerAddress: string,
message: TMsg,
message: TMsg | TMsg[],
fee: StdFee | 'auto',
memo: string
): Promise<DeliverTxResponse> => {
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputicjs/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export interface ReactMutationParams<TData, TError, TVariables, TContext = unkno
export interface UseMutationBuilderOptions<TMsg> {
builderMutationFn: (clientResolver?: SigningClientResolver) => (
signerAddress: string,
message: TMsg,
message: TMsg | TMsg[],
fee: StdFee | 'auto',
memo: string
) => Promise<DeliverTxResponse>,
Expand Down
14 changes: 13 additions & 1 deletion __fixtures__/v-next/outputinstantrpc/extern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ProtobufRpcClient> = {};

Expand Down Expand Up @@ -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);
}
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/akash/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/cosmos/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/evmos/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
14 changes: 13 additions & 1 deletion __fixtures__/v-next/outputv4/extern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ProtobufRpcClient> = {};

Expand Down Expand Up @@ -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);
}
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/ibc/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/osmosis/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions __fixtures__/v-next/outputv4/tendermint/rpc.query.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
Loading

0 comments on commit cd1ab64

Please sign in to comment.