diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d7fabb..e6bf9dc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to ## [Unreleased] +### Added + +- @cosmjs/tendermint-rpc: The options in the `HttpBatchClient` constructor are + now of type `Partial`, allowing you to set only the + fields you want to change ([#1309]). +- @cosmjs/tendermint-rpc: Add missing exports `HttpBatchClient`, + `HttpBatchClientOptions`, `RpcClient` ([#1311]). + +[#1309]: https://github.com/cosmos/cosmjs/issues/1309 +[#1311]: https://github.com/cosmos/cosmjs/issues/1311 + ### Fixed - @cosmjs/cosmwasm-stargate: Fix `ContractCodeHistory` decoding when msg diff --git a/packages/tendermint-rpc/src/index.ts b/packages/tendermint-rpc/src/index.ts index 8e307862..a1556d15 100644 --- a/packages/tendermint-rpc/src/index.ts +++ b/packages/tendermint-rpc/src/index.ts @@ -12,11 +12,17 @@ export { toRfc3339WithNanoseconds, toSeconds, } from "./dates"; +// The public Tendermint34Client.create constructor allows manually choosing an RpcClient. +// This is currently the only way to switch to the HttpBatchClient (which may become default at some point). +// Due to this API, we make RPC client implementations public. export { - // This type is part of the Tendermint34Client.connect API - HttpEndpoint, + HttpBatchClient, + HttpBatchClientOptions, + HttpClient, + HttpEndpoint, // This type is part of the Tendermint34Client.connect API + RpcClient, // Interface type in Tendermint34Client.create + WebsocketClient, } from "./rpcclients"; -export { HttpClient, WebsocketClient } from "./rpcclients"; // TODO: Why do we export those outside of this package? export { AbciInfoRequest, AbciInfoResponse, diff --git a/packages/tendermint-rpc/src/rpcclients/httpbatchclient.ts b/packages/tendermint-rpc/src/rpcclients/httpbatchclient.ts index f0bafc96..d91dc104 100644 --- a/packages/tendermint-rpc/src/rpcclients/httpbatchclient.ts +++ b/packages/tendermint-rpc/src/rpcclients/httpbatchclient.ts @@ -14,7 +14,10 @@ export interface HttpBatchClientOptions { batchSizeLimit: number; } -export const defaultHttpBatchClientOptions: HttpBatchClientOptions = { +// Those values are private and can change any time. +// Does a user need to know them? I don't think so. You either set +// a custom value or leave the option field unset. +const defaultHttpBatchClientOptions: HttpBatchClientOptions = { dispatchInterval: 20, batchSizeLimit: 20, }; @@ -31,11 +34,11 @@ export class HttpBatchClient implements RpcClient { reject: (a: Error) => void; }> = []; - public constructor( - endpoint: string | HttpEndpoint, - options: HttpBatchClientOptions = defaultHttpBatchClientOptions, - ) { - this.options = options; + public constructor(endpoint: string | HttpEndpoint, options: Partial = {}) { + this.options = { + batchSizeLimit: options.batchSizeLimit ?? defaultHttpBatchClientOptions.batchSizeLimit, + dispatchInterval: options.dispatchInterval ?? defaultHttpBatchClientOptions.dispatchInterval, + }; if (typeof endpoint === "string") { // accept host.name:port and assume http protocol this.url = hasProtocol(endpoint) ? endpoint : "http://" + endpoint; diff --git a/packages/tendermint-rpc/src/rpcclients/index.ts b/packages/tendermint-rpc/src/rpcclients/index.ts index cf7c1a70..ac89b9bb 100644 --- a/packages/tendermint-rpc/src/rpcclients/index.ts +++ b/packages/tendermint-rpc/src/rpcclients/index.ts @@ -1,6 +1,6 @@ // This folder contains Tendermint-specific RPC clients -export { defaultHttpBatchClientOptions, HttpBatchClient } from "./httpbatchclient"; +export { HttpBatchClient, HttpBatchClientOptions } from "./httpbatchclient"; export { HttpClient, HttpEndpoint } from "./httpclient"; export { instanceOfRpcStreamingClient, RpcClient, RpcStreamingClient, SubscriptionEvent } from "./rpcclient"; export { WebsocketClient } from "./websocketclient";