From 0aa02686743c01ae7392c3714d70b96830ef7a12 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 7 Mar 2023 10:30:26 +0100 Subject: [PATCH] Move version detection from Tendermint{34,37}Client.create to .connect --- .../src/tendermint34/tendermint34client.ts | 20 ++++++++++--------- .../src/tendermint37/tendermint37client.ts | 20 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/tendermint-rpc/src/tendermint34/tendermint34client.ts b/packages/tendermint-rpc/src/tendermint34/tendermint34client.ts index 282e07c809..c0538bfbba 100644 --- a/packages/tendermint-rpc/src/tendermint34/tendermint34client.ts +++ b/packages/tendermint-rpc/src/tendermint34/tendermint34client.ts @@ -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 { + 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 { - // 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); } diff --git a/packages/tendermint-rpc/src/tendermint37/tendermint37client.ts b/packages/tendermint-rpc/src/tendermint37/tendermint37client.ts index cdbbf164a9..9bbbc3117c 100644 --- a/packages/tendermint-rpc/src/tendermint37/tendermint37client.ts +++ b/packages/tendermint-rpc/src/tendermint37/tendermint37client.ts @@ -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 { + 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 { - // 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); }