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

(Don't Merge!) Test sample for multiple stargate client #697

Closed
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
86 changes: 86 additions & 0 deletions __fixtures__/v-next/outputinstantrpc/akash-cosmos-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing";
import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { HttpEndpoint } from "@cosmjs/tendermint-rpc";
import { createRpcClient } from "./extern";
import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "../outputcombinedclient/types";
import * as cosmosGroupV1TxAmino from "../outputcombinedclient/cosmos/group/v1/tx.amino";
import * as cosmosNftV1beta1TxAmino from "../outputcombinedclient/cosmos/nft/v1beta1/tx.amino";
import * as akashAuditV1beta1AuditAmino from "../outputcombinedclient/akash/audit/v1beta1/audit.amino";
import * as akashAuditV1beta2AuditAmino from "../outputcombinedclient/akash/audit/v1beta2/audit.amino";
import * as cosmosGroupV1TxRegistry from "../outputcombinedclient/cosmos/group/v1/tx.registry";
import * as cosmosNftV1beta1TxRegistry from "../outputcombinedclient/cosmos/nft/v1beta1/tx.registry";
import * as akashAuditV1beta1AuditRegistry from "../outputcombinedclient/akash/audit/v1beta1/audit.registry";
import * as akashAuditV1beta2AuditRegistry from "../outputcombinedclient/akash/audit/v1beta2/audit.registry";


export const akashCosmosConverters = {
...cosmosGroupV1TxAmino.AminoConverter,
...cosmosNftV1beta1TxAmino.AminoConverter,
...akashAuditV1beta1AuditAmino.AminoConverter,
...akashAuditV1beta2AuditAmino.AminoConverter,
};

export const akashCosmosProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosGroupV1TxRegistry.registry,
...cosmosNftV1beta1TxRegistry.registry,
...akashAuditV1beta1AuditRegistry.registry,
...akashAuditV1beta2AuditRegistry.registry,
];

export const getAkashCosmosSigningClientOptions = ({
defaultTypes = defaultRegistryTypes
}: {
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
} = {}): {
registry: Registry;
aminoTypes: AminoTypes;
} => {
const registry = new Registry([
...defaultTypes,
...akashCosmosProtoRegistry,
]);
const aminoTypes = new AminoTypes({
...akashCosmosConverters,
});
return {
registry,
aminoTypes
}
}

export const getAkashCosmosSigningClient = async ({
rpcEndpoint,
signer,
defaultTypes = defaultRegistryTypes
}: {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
}) => {
const {
registry,
aminoTypes
} = getAkashCosmosSigningClientOptions({
defaultTypes
});
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry: (registry as any),
aminoTypes
});
return client;
};

export const getAkashCosmosSigningTxRpc = async ({
rpcEndpoint,
signer
}: SigningClientParams) => {
let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc);
const signingClient = await getAkashCosmosSigningClient({
rpcEndpoint,
signer
});
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
81 changes: 81 additions & 0 deletions __fixtures__/v-next/outputinstantrpc/cosmos-ibc-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing";
import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { HttpEndpoint } from "@cosmjs/tendermint-rpc";
import { createRpcClient } from "./extern";
import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "../outputcombinedclient/types";
import * as ibcCoreChannelV1TxAmino from "../outputcombinedclient/ibc/core/channel/v1/tx.amino";
import * as ibcCoreChannelV1TxRegistry from "../outputcombinedclient/ibc/core/channel/v1/tx.registry";
import * as cosmosGovV1TxAmino from "../outputcombinedclient/cosmos/gov/v1/tx.amino";
import * as cosmosGovV1beta1TxAmino from "../outputcombinedclient/cosmos/gov/v1beta1/tx.amino";
import * as cosmosGovV1TxRegistry from "../outputcombinedclient/cosmos/gov/v1/tx.registry";
import * as cosmosGovV1beta1TxRegistry from "../outputcombinedclient/cosmos/gov/v1beta1/tx.registry";

export const cosmosIbcAminoConverters = {
...ibcCoreChannelV1TxAmino.AminoConverter,
...cosmosGovV1TxAmino.AminoConverter,
...cosmosGovV1beta1TxAmino.AminoConverter,
};

export const cosmosIbcProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...ibcCoreChannelV1TxRegistry.registry,
...cosmosGovV1TxRegistry.registry,
...cosmosGovV1beta1TxRegistry.registry,
];

export const getCosmosIbcSigningClientOptions = ({
defaultTypes = defaultRegistryTypes
}: {
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
} = {}): {
registry: Registry;
aminoTypes: AminoTypes;
} => {
const registry = new Registry([
...defaultTypes,
...cosmosIbcProtoRegistry,
]);
const aminoTypes = new AminoTypes({
...cosmosIbcAminoConverters,
});
return {
registry,
aminoTypes
}
}

export const getCosmosIbcSigningClient = async ({
rpcEndpoint,
signer,
defaultTypes = defaultRegistryTypes
}: {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
}) => {
const {
registry,
aminoTypes
} = getCosmosIbcSigningClientOptions({
defaultTypes
});
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry: (registry as any),
aminoTypes
});
return client;
};

export const getCosmosIbcSigningTxRpc = async ({
rpcEndpoint,
signer
}: SigningClientParams) => {
let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc);
const signingClient = await getCosmosIbcSigningClient({
rpcEndpoint,
signer
});
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
25 changes: 25 additions & 0 deletions packages/telescope/__tests__/telescope-instant-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,31 @@ const options: TelescopeOptions = {
},
},
],
combinedClient: [
{
name: "CosmosIbc",
fileName: "cosmos-ibc-client.ts",
include: {
patterns: [
"cosmos.gov.v1beta1.**",
"cosmos.gov.v1.**",
"ibc.core.channel.**",
],
},
},
{
name: "AkashCosmos",
fileName: "akash-cosmos-client.ts",
include: {
patterns: [
"cosmos.group.v1.**",
"cosmos.nft.v1beta1.**",
"akash.audit.v1beta1.**",
"akash.audit.v1beta2.**",
],
},
},
],
},

reactQuery: {
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ export interface TelescopeOpts {
};
}[];
useConnectComet?: boolean;
combinedClient?: {
name: string;
fileName: string;
include?: {
patterns?: string[];
};
}[];
};
helperFuncCreators?: {
enabled: boolean;
Expand Down
7 changes: 7 additions & 0 deletions packages/types/types/telescope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ export interface TelescopeOpts {
};
}[];
useConnectComet?: boolean;
combinedClient?: {
name: string;
fileName: string;
include?: {
patterns?: string[];
};
}[];
};
helperFuncCreators?: {
enabled: boolean;
Expand Down
Loading