Implement Tendermint auto-detection in StargateClient
This commit is contained in:
parent
f987f6af3a
commit
4c8c27cc37
@ -5,6 +5,7 @@ import { Uint53 } from "@cosmjs/math";
|
||||
import {
|
||||
HttpEndpoint,
|
||||
Tendermint34Client,
|
||||
Tendermint37Client,
|
||||
TendermintClient,
|
||||
toRfc3339WithNanoseconds,
|
||||
} from "@cosmjs/tendermint-rpc";
|
||||
@ -205,7 +206,18 @@ export class StargateClient {
|
||||
endpoint: string | HttpEndpoint,
|
||||
options: StargateClientOptions = {},
|
||||
): Promise<StargateClient> {
|
||||
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 StargateClient.create(tmClient, options);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user