Add Tendermint auto-detection to CosmWasmClient

This commit is contained in:
Simon Warta
2023-05-23 23:12:05 +02:00
parent 95c7cb2639
commit 5590c76024
4 changed files with 39 additions and 11 deletions
@@ -24,6 +24,7 @@ import {
import {
HttpEndpoint,
Tendermint34Client,
Tendermint37Client,
TendermintClient,
toRfc3339WithNanoseconds,
} from "@cosmjs/tendermint-rpc";
@@ -95,11 +96,22 @@ export class CosmWasmClient {
/**
* Creates an instance by connecting to the given Tendermint RPC endpoint.
*
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
* support, see `create`.
* This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client.
* To set the Tendermint client explicitly, use `create`.
*/
public static async connect(endpoint: string | HttpEndpoint): Promise<CosmWasmClient> {
const tmClient = await Tendermint34Client.connect(endpoint);
// 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 CosmWasmClient.create(tmClient);
}
@@ -31,7 +31,12 @@ import {
SignerData,
StdFee,
} from "@cosmjs/stargate";
import { HttpEndpoint, Tendermint34Client, TendermintClient } from "@cosmjs/tendermint-rpc";
import {
HttpEndpoint,
Tendermint34Client,
Tendermint37Client,
TendermintClient,
} from "@cosmjs/tendermint-rpc";
import { assert, assertDefined } from "@cosmjs/utils";
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
@@ -182,15 +187,26 @@ export class SigningCosmWasmClient extends CosmWasmClient {
/**
* Creates an instance by connecting to the given Tendermint RPC endpoint.
*
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
* support, see `createWithSigner`.
* This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client.
* To set the Tendermint client explicitly, use `createWithSigner`.
*/
public static async connectWithSigner(
endpoint: string | HttpEndpoint,
signer: OfflineSigner,
options: SigningCosmWasmClientOptions = {},
): Promise<SigningCosmWasmClient> {
const tmClient = await Tendermint34Client.connect(endpoint);
// 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 SigningCosmWasmClient.createWithSigner(tmClient, signer, options);
}
@@ -118,8 +118,8 @@ export class SigningStargateClient extends StargateClient {
/**
* Creates an instance by connecting to the given Tendermint RPC endpoint.
*
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
* support, see `createWithSigner`.
* This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client.
* To set the Tendermint client explicitly, use `createWithSigner`.
*/
public static async connectWithSigner(
endpoint: string | HttpEndpoint,
+2 -2
View File
@@ -193,8 +193,8 @@ export class StargateClient {
/**
* Creates an instance by connecting to the given Tendermint RPC endpoint.
*
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
* support, see `create`.
* This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client.
* To set the Tendermint client explicitly, use `create`.
*/
public static async connect(
endpoint: string | HttpEndpoint,