Merge pull request #1380 from cosmos/tendermint-detect-in-connect

Move version detection from Tendermint{34,37}Client.create to .connect
This commit is contained in:
Simon Warta 2023-03-15 12:15:46 +01:00 committed by GitHub
commit d2ad114218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 18 deletions

View File

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Stream } from "xstream";
import { createJsonRpcRequest } from "../jsonrpc";
@ -21,24 +20,27 @@ export class Tendermint34Client {
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
*/
public static async connect(endpoint: string | HttpEndpoint): Promise<Tendermint34Client> {
let rpcClient: RpcClient;
if (typeof endpoint === "object") {
return Tendermint34Client.create(new HttpClient(endpoint));
rpcClient = new HttpClient(endpoint);
} else {
const useHttp = endpoint.startsWith("http://") || endpoint.startsWith("https://");
const rpcClient = useHttp ? new HttpClient(endpoint) : new WebsocketClient(endpoint);
return Tendermint34Client.create(rpcClient);
rpcClient = useHttp ? new HttpClient(endpoint) : new WebsocketClient(endpoint);
}
// For some very strange reason I don't understand, tests start to fail on some systems
// (our CI) when skipping the status call before doing other queries. Sleeping a little
// while did not help. Thus we query the version as a way to say "hi" to the backend,
// even in cases where we don't use the result.
const _version = await this.detectVersion(rpcClient);
return Tendermint34Client.create(rpcClient);
}
/**
* Creates a new Tendermint client given an RPC client.
*/
public static async create(rpcClient: RpcClient): Promise<Tendermint34Client> {
// For some very strange reason I don't understand, tests start to fail on some systems
// (our CI) when skipping the status call before doing other queries. Sleeping a little
// while did not help. Thus we query the version as a way to say "hi" to the backend,
// even in cases where we don't use the result.
const _version = await this.detectVersion(rpcClient);
return new Tendermint34Client(rpcClient);
}

View File

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Stream } from "xstream";
import { createJsonRpcRequest } from "../jsonrpc";
@ -21,24 +20,27 @@ export class Tendermint37Client {
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
*/
public static async connect(endpoint: string | HttpEndpoint): Promise<Tendermint37Client> {
let rpcClient: RpcClient;
if (typeof endpoint === "object") {
return Tendermint37Client.create(new HttpClient(endpoint));
rpcClient = new HttpClient(endpoint);
} else {
const useHttp = endpoint.startsWith("http://") || endpoint.startsWith("https://");
const rpcClient = useHttp ? new HttpClient(endpoint) : new WebsocketClient(endpoint);
return Tendermint37Client.create(rpcClient);
rpcClient = useHttp ? new HttpClient(endpoint) : new WebsocketClient(endpoint);
}
// For some very strange reason I don't understand, tests start to fail on some systems
// (our CI) when skipping the status call before doing other queries. Sleeping a little
// while did not help. Thus we query the version as a way to say "hi" to the backend,
// even in cases where we don't use the result.
const _version = await this.detectVersion(rpcClient);
return Tendermint37Client.create(rpcClient);
}
/**
* Creates a new Tendermint client given an RPC client.
*/
public static async create(rpcClient: RpcClient): Promise<Tendermint37Client> {
// For some very strange reason I don't understand, tests start to fail on some systems
// (our CI) when skipping the status call before doing other queries. Sleeping a little
// while did not help. Thus we query the version as a way to say "hi" to the backend,
// even in cases where we don't use the result.
const _version = await this.detectVersion(rpcClient);
return new Tendermint37Client(rpcClient);
}