Skip to content

Commit

Permalink
Merge pull request #731 from hyperweb-io/interchainjs-deps
Browse files Browse the repository at this point in the history
fix extern, types, vue-query
  • Loading branch information
Zetazzz authored Feb 13, 2025
2 parents 280d0d3 + 6f533c2 commit 7b7afd6
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 93 deletions.
1 change: 1 addition & 0 deletions __fixtures__/misc/output-impl-interfaces-gen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputhelperfunc/extern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { HttpEndpoint } from "@interchainjs/types";
import {
createQueryRpc,
} from '@interchainjs/cosmos/utils';
} from '@interchainjs/utils';
import { Rpc } from "./helpers";

const _rpcClients: Record<string, Rpc> = {};
Expand Down
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputhelperfunc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

31 changes: 3 additions & 28 deletions __fixtures__/v-next/outputhelperfunc/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import {
QueryKey,
} from '@tanstack/vue-query';

import { HttpEndpoint, ProtobufRpcClient } from '@cosmjs/stargate';
import { CometClient, connectComet, Tendermint34Client, Tendermint37Client } from '@cosmjs/tendermint-rpc';
import { HttpEndpoint } from "@interchainjs/types";
import { Rpc as ProtobufRpcClient } from "./helpers";

import {Ref} from 'vue'

export const DEFAULT_RPC_CLIENT_QUERY_KEY = 'rpcClient';
Expand Down Expand Up @@ -111,32 +112,6 @@ export function useRpcClient<TData = ProtobufRpcClient>({
);
}

interface UseTendermintClient extends VueQueryParams<Tendermint34Client | Tendermint37Client | CometClient> {
rpcEndpoint: string | HttpEndpoint;
}

/**
* Function that uses vue-query to cache a connected tendermint client.
*/
export const useTendermintClient = ({
rpcEndpoint,
options,
}: UseTendermintClient) => {
const { data: client } = useQuery<Tendermint34Client | Tendermint37Client | CometClient, Error, Tendermint34Client | Tendermint37Client | CometClient>({
queryKey: ['client', 'tendermint', rpcEndpoint],
queryFn: () => connectComet(rpcEndpoint),
...{
// allow overriding
onError: (e: any) => {
throw new Error(`Failed to connect to ${rpcEndpoint}` + '\n' + e)
},
...options,
}
}
);
return { client };
};

export interface UseQueryBuilderOptions<TReq, TRes> {
builderQueryFn: (
clientResolver?: RpcResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Duration, DurationAmino } from "../../../google/protobuf/duration";
import { Coin, CoinAmino } from "../../base/v1beta1/coin";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { encodePubkey, decodePubkey } from "@interchainjs/pubkey";
import { Pubkey } from "@cosmjs/amino";
/** BondStatus is the status of a validator. */
export enum BondStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Coin, CoinAmino } from "../../base/v1beta1/coin";
import { Timestamp } from "../../../google/protobuf/timestamp";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { encodePubkey, decodePubkey } from "@interchainjs/pubkey";
import { Pubkey } from "@cosmjs/amino";
/** MsgCreateValidator defines a SDK message for creating a new validator. */
export interface MsgCreateValidator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AccessConfig, AccessConfigAmino } from "./types";
import { Coin, CoinAmino } from "../../../cosmos/base/v1beta1/coin";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial } from "../../../helpers";
import { fromBase64, toBase64, toUtf8, fromUtf8 } from "@cosmjs/encoding";
import { fromBase64, toBase64, toUtf8, fromUtf8 } from "@interchainjs/encoding";
/** StoreCodeProposal gov proposal content type to submit WASM code to the system */
export interface StoreCodeProposal {
/** Title is a short summary */
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputicjs/cosmwasm/wasm/v1/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PageRequest, PageRequestAmino, PageResponse, PageResponseAmino } from "
import { ContractInfo, ContractInfoAmino, ContractCodeHistoryEntry, ContractCodeHistoryEntryAmino, Model, ModelAmino } from "./types";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial, bytesFromBase64, base64FromBytes } from "../../../helpers";
import { toUtf8, fromUtf8 } from "@cosmjs/encoding";
import { toUtf8, fromUtf8 } from "@interchainjs/encoding";
/**
* QueryContractInfoRequest is the request type for the Query/ContractInfo RPC
* method
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputicjs/cosmwasm/wasm/v1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AccessConfig, AccessConfigAmino } from "./types";
import { Coin, CoinAmino } from "../../../cosmos/base/v1beta1/coin";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial, bytesFromBase64, base64FromBytes } from "../../../helpers";
import { fromBase64, toBase64, toUtf8, fromUtf8 } from "@cosmjs/encoding";
import { fromBase64, toBase64, toUtf8, fromUtf8 } from "@interchainjs/encoding";
/** MsgStoreCode submit Wasm code to the system */
export interface MsgStoreCode {
/** Sender is the that actor that signed the messages */
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputicjs/cosmwasm/wasm/v1/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Any, AnyProtoMsg, AnyAmino } from "../../../google/protobuf/any";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { DeepPartial, bytesFromBase64, base64FromBytes } from "../../../helpers";
import { toUtf8, fromUtf8 } from "@cosmjs/encoding";
import { toUtf8, fromUtf8 } from "@interchainjs/encoding";
/** AccessType permission types */
export enum AccessType {
/** ACCESS_TYPE_UNSPECIFIED - AccessTypeUnspecified placeholder for empty value */
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/v-next/outputicjs/extern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { HttpEndpoint } from "@interchainjs/types";
import {
createQueryRpc,
} from '@interchainjs/cosmos/utils';
} from '@interchainjs/utils';
import { Rpc } from "./helpers";

const _rpcClients: Record<string, Rpc> = {};
Expand Down
6 changes: 1 addition & 5 deletions __fixtures__/v-next/outputicjs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { IBinaryReader, IBinaryWriter } from "./binary";
import { Any } from "./google/protobuf/any";
import { OfflineSigner } from "@interchainjs/cosmos/types/wallet";

import { HttpEndpoint } from "@interchainjs/types";

export type ProtoMsg = Omit<Any, "typeUrl"> & { typeUrl: any };
Expand Down Expand Up @@ -150,7 +150,3 @@ export interface TxRpc {
): Promise<DeliverTxResponse>;
}

export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

1 change: 1 addition & 0 deletions __fixtures__/v-next/outputsign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}

12 changes: 12 additions & 0 deletions packages/telescope/src/generators/customize-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import { TelescopeBuilder } from '../builder';
import { UTILS } from '../utils';

export const plugin = (builder: TelescopeBuilder) => {
if(builder.options.useInterchainJs) {
UTILS.encodePubkey = '@interchainjs/pubkey';
UTILS.decodePubkey = '@interchainjs/pubkey';

UTILS.fromBase64 = '@interchainjs/encoding';
UTILS.fromBech32 = '@interchainjs/encoding';
UTILS.fromHex = '@interchainjs/encoding';
UTILS.fromUtf8 = '@interchainjs/encoding';
UTILS.toBase64 = '@interchainjs/encoding';
UTILS.toUtf8 = '@interchainjs/encoding';
}

if (
builder.options.prototypes.typingsFormat.customTypes.useEnhancedDecimal ===
true
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/src/helpers/external-icjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const externalIcJs = `
import { HttpEndpoint } from "@interchainjs/types";
import {
createQueryRpc,
} from '@interchainjs/cosmos/utils';
} from '@interchainjs/utils';
import { Rpc } from "./helpers";
const _rpcClients: Record<string, Rpc> = {};
Expand Down
9 changes: 3 additions & 6 deletions packages/telescope/src/helpers/types-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export const getTypesHelper = (options: TelescopeOptions) => {
import { Any } from "./google/protobuf/any${
options.restoreImportExtension ?? ""
}";
import { OfflineSigner } from "${
options.useInterchainJs
? "@interchainjs/cosmos/types/wallet"
: "@cosmjs/proto-signing"
}";
${options.useInterchainJs ? '' : `import { OfflineSigner } from "@cosmjs/proto-signing";`}
import { HttpEndpoint } from "${
options.useInterchainJs ? "@interchainjs/types" : "@cosmjs/tendermint-rpc"
}";
Expand Down Expand Up @@ -156,10 +152,11 @@ export interface TxRpc {
memo: string
): Promise<DeliverTxResponse>;
}
${options.useInterchainJs ? '' : `
export interface SigningClientParams {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
}
`}
`;
};
47 changes: 3 additions & 44 deletions packages/telescope/src/helpers/vue-query-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ import {
QueryKey,
} from '@tanstack/vue-query';
import { HttpEndpoint, ProtobufRpcClient } from '@cosmjs/stargate';
${
options.rpcClients.useConnectComet
? "import { CometClient, connectComet, Tendermint34Client, Tendermint37Client } from '@cosmjs/tendermint-rpc';"
: "import { Tendermint34Client } from '@cosmjs/tendermint-rpc';"
}
import { HttpEndpoint } from "@interchainjs/types";
import { Rpc as ProtobufRpcClient } from "./helpers${options.restoreImportExtension ?? ""}";
import {Ref} from 'vue'
export const DEFAULT_RPC_CLIENT_QUERY_KEY = 'rpcClient';
Expand Down Expand Up @@ -112,44 +109,6 @@ export function useRpcClient<TData = ProtobufRpcClient>({
);
}
${
options.rpcClients.useConnectComet
? "interface UseTendermintClient extends VueQueryParams<Tendermint34Client | Tendermint37Client | CometClient> {"
: "interface UseTendermintClient extends VueQueryParams<Tendermint34Client> {"
}
rpcEndpoint: string | HttpEndpoint;
}
/**
* Function that uses vue-query to cache a connected tendermint client.
*/
export const useTendermintClient = ({
rpcEndpoint,
options,
}: UseTendermintClient) => {
${
options.rpcClients.useConnectComet
? " const { data: client } = useQuery<Tendermint34Client | Tendermint37Client | CometClient, Error, Tendermint34Client | Tendermint37Client | CometClient>({"
: " const { data: client } = useQuery<Tendermint34Client, Error, Tendermint34Client>({"
}
queryKey: ['client', 'tendermint', rpcEndpoint],
queryFn: () => ${
options.rpcClients.useConnectComet
? "connectComet(rpcEndpoint)"
: "Tendermint34Client.connect(rpcEndpoint)"
},
...{
// allow overriding
onError: (e: any) => {
throw new Error(\`Failed to connect to \${rpcEndpoint}\` + '\\n' + e)
},
...options,
}
}
);
return { client };
};
export interface UseQueryBuilderOptions<TReq, TRes> {
builderQueryFn: (
clientResolver?: RpcResolver
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/types/helpers/external-icjs.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const externalIcJs = "\nimport { HttpEndpoint } from \"@interchainjs/types\";\nimport {\n createQueryRpc,\n} from '@interchainjs/cosmos/utils';\nimport { Rpc } from \"./helpers\";\n\nconst _rpcClients: Record<string, Rpc> = {};\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 rpc = await createRpcClient(rpcEndpoint);\n _rpcClients[key] = rpc;\n return rpc;\n}\n\nexport const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n return createQueryRpc(rpcEndpoint)\n}\n";
export declare const externalIcJs = "\nimport { HttpEndpoint } from \"@interchainjs/types\";\nimport {\n createQueryRpc,\n} from '@interchainjs/utils';\nimport { Rpc } from \"./helpers\";\n\nconst _rpcClients: Record<string, Rpc> = {};\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 rpc = await createRpcClient(rpcEndpoint);\n _rpcClients[key] = rpc;\n return rpc;\n}\n\nexport const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n return createQueryRpc(rpcEndpoint)\n}\n";

0 comments on commit 7b7afd6

Please sign in to comment.