Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move version detection from Tendermint{34,37}Client.create to .connect #1380

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/tendermint-rpc/src/tendermint34/tendermint34client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Stream } from "xstream";

import { createJsonRpcRequest } from "../jsonrpc";
Expand All @@ -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);
}
}

/**
* 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 Tendermint34Client.create(rpcClient);
}

/**
* Creates a new Tendermint client given an RPC client.
*/
public static async create(rpcClient: RpcClient): Promise<Tendermint34Client> {
return new Tendermint34Client(rpcClient);
}

Expand Down
20 changes: 11 additions & 9 deletions packages/tendermint-rpc/src/tendermint37/tendermint37client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Stream } from "xstream";

import { createJsonRpcRequest } from "../jsonrpc";
Expand All @@ -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);
}
}

/**
* 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 Tendermint37Client.create(rpcClient);
}

/**
* Creates a new Tendermint client given an RPC client.
*/
public static async create(rpcClient: RpcClient): Promise<Tendermint37Client> {
return new Tendermint37Client(rpcClient);
}

Expand Down