Improve CometBFT support in high level clients
This commit is contained in:
parent
6a877027f6
commit
5eb7d8ba33
10
CHANGELOG.md
10
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
|
||||
|
||||
@ -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<CosmWasmClient> {
|
||||
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<CosmWasmClient> {
|
||||
return new CosmWasmClient(cometClient);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<SigningStargateClient> {
|
||||
// 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<SigningStargateClient> {
|
||||
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()),
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user