-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: batch client creation, better handle disconnects (#123)
- Loading branch information
Showing
4 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import { Tendermint37Client, RpcClient, Comet38Client, Tendermint34Client, CometClient } from '@cosmjs/tendermint-rpc'; | ||
import { | ||
Comet38Client, | ||
CometClient, | ||
HttpEndpoint, | ||
HttpBatchClientOptions, | ||
HttpBatchClient, | ||
RpcClient, | ||
Tendermint37Client, | ||
Tendermint34Client, | ||
} from '@cosmjs/tendermint-rpc'; | ||
|
||
/** | ||
* Auto-detects Tendermint/CometBFT 0.34/0.37/0.38 version for connecting to an RPC Client. | ||
* Auto-detects Tendermint/CometBFT 0.34/0.37/0.38 version for connecting to an RPC Client with an HttpBatchClient. | ||
* | ||
* @param rpcClient - Instance of {@link RpcClient} to connect to. | ||
* @returns Suitable client version of {@link CometClient}. | ||
* @param endpoint - String URL of the RPC endpoint to connect or an {@link HttpEndpoint} object. | ||
* @param options - Optional configuration to control how the {@link HttpBatchClient} will batch requests. | ||
*/ | ||
export async function connectToRpcClient(rpcClient: RpcClient): Promise<CometClient> { | ||
export async function connectCometWithBatchClient( | ||
endpoint: string | HttpEndpoint, | ||
options?: Partial<HttpBatchClientOptions>, | ||
): Promise<CometClient> { | ||
let rpcClient: RpcClient = new HttpBatchClient(endpoint, options); | ||
const tendermint37Client = await Tendermint37Client.create(rpcClient); | ||
const version = (await tendermint37Client.status()).nodeInfo.version; | ||
|
||
// HACK: Force Tendermint37Client on 0.38.x versions, remove when client batching issue is fixed | ||
if (version.startsWith('0.37.') || version.startsWith('0.38.')) { | ||
if (version.startsWith('0.37.')) { | ||
return tendermint37Client; | ||
} | ||
|
||
tendermint37Client.disconnect(); | ||
rpcClient.disconnect(); | ||
|
||
// if (version.startsWith('0.38.')) { | ||
// console.log('VERRRRR2222',version) | ||
// return await Comet38Client.create(rpcClient); | ||
// } | ||
rpcClient = new HttpBatchClient(endpoint, options); | ||
|
||
if (version.startsWith('0.38.')) { | ||
return await Comet38Client.create(rpcClient); | ||
} | ||
|
||
return await Tendermint34Client.create(rpcClient); | ||
} |