From 5eb7d8ba336bd4aa926dbb923026a8c1abc655e5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 25 Oct 2023 14:54:26 +0200 Subject: [PATCH] Improve CometBFT support in high level clients --- CHANGELOG.md | 10 +++++ .../cosmwasm-stargate/src/cosmwasmclient.ts | 10 ++--- .../src/signingcosmwasmclient.ts | 10 ++--- .../stargate/src/signingstargateclient.ts | 40 ++++++------------- packages/stargate/src/stargateclient.ts | 10 ++--- 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2f7832..fe6d1d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,16 @@ and this project adheres to - @cosmjs/tendermint-rpc: Add `CometClient = Tendermint34Client | Tendermint37Client | Comet38Client` and `connectComet` for auto-detecting the right client for a provided endpoint. +- @cosmjs/stargate: Let `SigningStargateClient.createWithSigner` and + `StargateClient.create` take a `CometClient` argument, adding support for + `Comet38Client`. The auto-detection in + `SigningStargateClient.connectWithSigner` and `StargateClient.connect` now + supports CometBFT 0.38. +- @cosmjs/cosmwasm-stargate: Let `SigningCosmWasmClient.createWithSigner` and + `CosmWasmClient.create` take a `CometClient` argument, adding support for + `Comet38Client`. The auto-detection in + `SigningCosmWasmClient.connectWithSigner` and `CosmWasmClient.connect` now + supports CometBFT 0.38. [#1421]: https://github.com/cosmos/cosmjs/issues/1421 [#1484]: https://github.com/cosmos/cosmjs/pull/1484 diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index 7a825196..7c35d797 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -90,10 +90,10 @@ export class CosmWasmClient { private chainId: string | undefined; /** - * Creates an instance by connecting to the given Tendermint RPC endpoint. + * Creates an instance by connecting to the given CometBFT RPC endpoint. * - * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. - * To set the Tendermint client explicitly, use `create`. + * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client. + * To set the Comet client explicitly, use `create`. */ public static async connect(endpoint: string | HttpEndpoint): Promise { const cometClient = await connectComet(endpoint); @@ -101,8 +101,8 @@ export class CosmWasmClient { } /** - * Creates an instance from a manually created Tendermint client. - * Use this to use `Tendermint37Client` instead of `Tendermint34Client`. + * Creates an instance from a manually created Comet client. + * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. */ public static async create(cometClient: CometClient): Promise { return new CosmWasmClient(cometClient); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 6de59caf..ab80616b 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -180,10 +180,10 @@ export class SigningCosmWasmClient extends CosmWasmClient { private readonly gasPrice: GasPrice | undefined; /** - * Creates an instance by connecting to the given Tendermint RPC endpoint. + * Creates an instance by connecting to the given CometBFT RPC endpoint. * - * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. - * To set the Tendermint client explicitly, use `createWithSigner`. + * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client. + * To set the Comet client explicitly, use `createWithSigner`. */ public static async connectWithSigner( endpoint: string | HttpEndpoint, @@ -195,8 +195,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { } /** - * Creates an instance from a manually created Tendermint client. - * Use this to use `Tendermint37Client` instead of `Tendermint34Client`. + * Creates an instance from a manually created Comet client. + * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. */ public static async createWithSigner( cometClient: CometClient, diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index c468502f..e649e869 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -12,12 +12,7 @@ import { Registry, TxBodyEncodeObject, } from "@cosmjs/proto-signing"; -import { - HttpEndpoint, - Tendermint34Client, - Tendermint37Client, - TendermintClient, -} from "@cosmjs/tendermint-rpc"; +import { CometClient, connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; @@ -117,41 +112,30 @@ export class SigningStargateClient extends StargateClient { private readonly gasPrice: GasPrice | undefined; /** - * Creates an instance by connecting to the given Tendermint RPC endpoint. + * Creates an instance by connecting to the given CometBFT RPC endpoint. * - * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. - * To set the Tendermint client explicitly, use `createWithSigner`. + * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client. + * To set the Comet client explicitly, use `createWithSigner`. */ public static async connectWithSigner( endpoint: string | HttpEndpoint, signer: OfflineSigner, options: SigningStargateClientOptions = {}, ): Promise { - // Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉 - // Using 0.34 as the fallback. - let tmClient: TendermintClient; - const tm37Client = await Tendermint37Client.connect(endpoint); - const version = (await tm37Client.status()).nodeInfo.version; - if (version.startsWith("0.37.")) { - tmClient = tm37Client; - } else { - tm37Client.disconnect(); - tmClient = await Tendermint34Client.connect(endpoint); - } - - return SigningStargateClient.createWithSigner(tmClient, signer, options); + const cometClient = await connectComet(endpoint); + return SigningStargateClient.createWithSigner(cometClient, signer, options); } /** - * Creates an instance from a manually created Tendermint client. - * Use this to use `Tendermint37Client` instead of `Tendermint34Client`. + * Creates an instance from a manually created Comet client. + * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. */ public static async createWithSigner( - tmClient: TendermintClient, + cometClient: CometClient, signer: OfflineSigner, options: SigningStargateClientOptions = {}, ): Promise { - return new SigningStargateClient(tmClient, signer, options); + return new SigningStargateClient(cometClient, signer, options); } /** @@ -171,11 +155,11 @@ export class SigningStargateClient extends StargateClient { } protected constructor( - tmClient: TendermintClient | undefined, + cometClient: CometClient | undefined, signer: OfflineSigner, options: SigningStargateClientOptions, ) { - super(tmClient, options); + super(cometClient, options); const { registry = new Registry(defaultRegistryTypes), aminoTypes = new AminoTypes(createDefaultAminoConverters()), diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 69ff4582..8022d2d5 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -198,10 +198,10 @@ export class StargateClient { private readonly accountParser: AccountParser; /** - * Creates an instance by connecting to the given Tendermint RPC endpoint. + * Creates an instance by connecting to the given CometBFT RPC endpoint. * - * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. - * To set the Tendermint client explicitly, use `create`. + * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client. + * To set the Comet client explicitly, use `create`. */ public static async connect( endpoint: string | HttpEndpoint, @@ -212,8 +212,8 @@ export class StargateClient { } /** - * Creates an instance from a manually created Tendermint client. - * Use this to use `Tendermint37Client` instead of `Tendermint34Client`. + * Creates an instance from a manually created Comet client. + * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`. */ public static async create( cometClient: CometClient,