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

Add Client class to serve as a general purpose base without message types #1486

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
688 changes: 688 additions & 0 deletions packages/stargate/src/client.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/stargate/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromUtf8 } from "@cosmjs/encoding";
import { tendermint34, tendermint37 } from "@cosmjs/tendermint-rpc";
import { comet38, tendermint34, tendermint37 } from "@cosmjs/tendermint-rpc";

/**
* An event attribute.
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface Event {
* Takes a Tendermint 0.34 or 0.37 event with binary encoded key and value
* and converts it into an `Event` with string attributes.
*/
export function fromTendermintEvent(event: tendermint34.Event | tendermint37.Event): Event {
export function fromTendermintEvent(event: tendermint34.Event | tendermint37.Event | comet38.Event): Event {
return {
type: event.type,
attributes: event.attributes.map(
Expand Down
31 changes: 16 additions & 15 deletions packages/stargate/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
export { Account, accountFromAny, AccountParser } from "./accounts";
export { AminoConverter, AminoConverters, AminoTypes } from "./aminotypes";
export {
assertIsDeliverTxFailure,
assertIsDeliverTxSuccess,
Block,
BlockHeader,
BroadcastTxError,
Client,
ClientOptions,
DeliverTxResponse,
IndexedTx,
isDeliverTxFailure,
isDeliverTxSuccess,
SequenceResponse,
TimeoutError,
} from "./client";
export { Attribute, Event, fromTendermintEvent } from "./events";
export { calculateFee, GasPrice } from "./fee";
export * as logs from "./logs";
Expand Down Expand Up @@ -121,21 +136,7 @@ export {
SigningStargateClient,
SigningStargateClientOptions,
} from "./signingstargateclient";
export {
assertIsDeliverTxFailure,
assertIsDeliverTxSuccess,
Block,
BlockHeader,
BroadcastTxError,
DeliverTxResponse,
IndexedTx,
isDeliverTxFailure,
isDeliverTxSuccess,
SequenceResponse,
StargateClient,
StargateClientOptions,
TimeoutError,
} from "./stargateclient";
export { StargateClient, StargateClientOptions } from "./stargateclient";
export { StdFee } from "@cosmjs/amino";
export { Coin, coin, coins, makeCosmoshubPath, parseCoins } from "@cosmjs/proto-signing";

Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/authz/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assertDefined, sleep } from "@cosmjs/utils";
import { GenericAuthorization } from "cosmjs-types/cosmos/authz/v1beta1/authz";

import { assertIsDeliverTxSuccess } from "../../client";
import { QueryClient } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/distribution/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { sleep } from "@cosmjs/utils";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";

import { assertIsDeliverTxSuccess } from "../../client";
import { QueryClient } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/gov/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { assert, sleep } from "@cosmjs/utils";
import { TextProposal, VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { Any } from "cosmjs-types/google/protobuf/any";

import { assertIsDeliverTxSuccess } from "../../client";
import { longify } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/gov/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";

import { assertIsDeliverTxSuccess } from "../../client";
import { longify, QueryClient } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/staking/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Random } from "@cosmjs/crypto";
import { fromBech32, toBase64, toBech32 } from "@cosmjs/encoding";
import { DirectSecp256k1HdWallet, encodePubkey } from "@cosmjs/proto-signing";

import { assertIsDeliverTxSuccess } from "../../client";
import { calculateFee } from "../../fee";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultGasPrice,
defaultSigningClientOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/staking/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { sleep } from "@cosmjs/utils";
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";

import { assertIsDeliverTxSuccess } from "../../client";
import { QueryClient } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
3 changes: 2 additions & 1 deletion packages/stargate/src/modules/tx/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { assertDefined, sleep } from "@cosmjs/utils";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import Long from "long";

import { assertIsDeliverTxSuccess } from "../../client";
import { QueryClient } from "../../queryclient";
import { defaultRegistryTypes, SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess, StargateClient } from "../../stargateclient";
import { StargateClient } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/vesting/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";

import { assertIsDeliverTxSuccess } from "../../client";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
3 changes: 2 additions & 1 deletion packages/stargate/src/multisignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { coins } from "@cosmjs/proto-signing";
import { assert } from "@cosmjs/utils";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";

import { assertIsDeliverTxSuccess } from "./client";
import { MsgSendEncodeObject } from "./modules";
import { makeCompactBitArray, makeMultisignedTxBytes } from "./multisignature";
import { SignerData, SigningStargateClient } from "./signingstargateclient";
import { assertIsDeliverTxSuccess, StargateClient } from "./stargateclient";
import { StargateClient } from "./stargateclient";
import { faucet, pendingWithoutSimapp, simapp } from "./testutils.spec";

describe("multisignature", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/signingstargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Long from "long";
import protobuf from "protobufjs/minimal";

import { AminoTypes } from "./aminotypes";
import { assertIsDeliverTxFailure, assertIsDeliverTxSuccess, isDeliverTxFailure } from "./client";
import {
AminoMsgDelegate,
MsgDelegateEncodeObject,
Expand All @@ -34,7 +35,6 @@ import {
SigningStargateClient,
SigningStargateClientOptions,
} from "./signingstargateclient";
import { assertIsDeliverTxFailure, assertIsDeliverTxSuccess, isDeliverTxFailure } from "./stargateclient";
import {
defaultGasPrice,
defaultSendFee,
Expand Down
3 changes: 2 additions & 1 deletion packages/stargate/src/signingstargateclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Height } from "cosmjs-types/ibc/core/client/v1/client";
import Long from "long";

import { AminoConverters, AminoTypes } from "./aminotypes";
import { DeliverTxResponse } from "./client";
import { calculateFee, GasPrice } from "./fee";
import {
authzTypes,
Expand Down Expand Up @@ -56,7 +57,7 @@ import {
createStakingAminoConverters,
createVestingAminoConverters,
} from "./modules";
import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient";
import { StargateClient, StargateClientOptions } from "./stargateclient";

export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
["/cosmos.base.v1beta1.Coin", Coin],
Expand Down
3 changes: 2 additions & 1 deletion packages/stargate/src/stargateclient.searchtx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { MsgSendResponse } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";

import { DeliverTxResponse, isDeliverTxFailure, isDeliverTxSuccess } from "./client";
import { isMsgSendEncodeObject } from "./modules";
import { DeliverTxResponse, isDeliverTxFailure, isDeliverTxSuccess, StargateClient } from "./stargateclient";
import { StargateClient } from "./stargateclient";
import {
defaultSigningClientOptions,
faucet,
Expand Down
7 changes: 3 additions & 4 deletions packages/stargate/src/stargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
DeliverTxResponse,
isDeliverTxFailure,
isDeliverTxSuccess,
PrivateStargateClient,
StargateClient,
TimeoutError,
} from "./stargateclient";
} from "./client";
import { PrivateStargateClient, StargateClient } from "./stargateclient";
import {
faucet,
makeRandomAddress,
Expand Down Expand Up @@ -98,7 +97,7 @@ describe("StargateClient", () => {
pendingWithoutSimapp();
const client = await StargateClient.connect(simapp.tendermintUrl);
const openedClient = client as unknown as PrivateStargateClient;
const getCodeSpy = spyOn(openedClient.cometClient!, "status").and.callThrough();
const getCodeSpy = spyOn(openedClient.client.cometClient!, "status").and.callThrough();

expect(await client.getChainId()).toEqual(simapp.chainId); // from network
expect(await client.getChainId()).toEqual(simapp.chainId); // from cache
Expand Down
Loading