diff --git a/changelog.md b/changelog.md index 8d53b6d7..d008b2f5 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). #### **arch3-core** +- added support to create an `SigningArchwayClient` using an + `HttpBatchClient` (#97) - added support to create an `ArchwayClient` using an `HttpBatchClient` (#96) ### Changes @@ -40,7 +42,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). #### **arch3-core** -- method to `calculateFees` for multiple messages on `SigningArchwayClient` (#86) +- method to `calculateFees` for multiple messages on + `SigningArchwayClient` (#86) ### Changes diff --git a/packages/arch3-core/src/archwayclient.ts b/packages/arch3-core/src/archwayclient.ts index 060b3395..1bb7e39d 100644 --- a/packages/arch3-core/src/archwayclient.ts +++ b/packages/arch3-core/src/archwayclient.ts @@ -45,7 +45,7 @@ export class ArchwayClient extends CosmWasmClient implements IArchwayQueryClient /** * Creates an instance by connecting to the given Tendermint RPC endpoint using an {@link HttpBatchClient} to batch - * multiple requests and increase the app performance. + * multiple requests and reduce queries to the server. * * @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. diff --git a/packages/arch3-core/src/signingarchwayclient.spec.ts b/packages/arch3-core/src/signingarchwayclient.spec.ts index a9e46305..f3cbc2ff 100644 --- a/packages/arch3-core/src/signingarchwayclient.spec.ts +++ b/packages/arch3-core/src/signingarchwayclient.spec.ts @@ -67,6 +67,15 @@ describe('SigningArchwayClient', () => { }); }); + describe('connectWithSignerAndBatchClient', () => { + it('can be constructed', async () => { + const wallet = await DirectSecp256k1HdWallet.generate(12, { prefix: archwayd.prefix }); + const client = await SigningArchwayClient.connectWithSignerAndBatchClient(archwayd.endpoint, wallet, clientOptions); + expect(client).toBeDefined(); + client.disconnect(); + }); + }); + describe('offline', () => { it('can be constructed', async () => { const wallet = await DirectSecp256k1HdWallet.generate(12, { prefix: archwayd.prefix }); diff --git a/packages/arch3-core/src/signingarchwayclient.ts b/packages/arch3-core/src/signingarchwayclient.ts index b82ccb20..c49d54fb 100644 --- a/packages/arch3-core/src/signingarchwayclient.ts +++ b/packages/arch3-core/src/signingarchwayclient.ts @@ -18,7 +18,13 @@ import { logs, StdFee } from '@cosmjs/stargate'; -import { Tendermint34Client, TendermintClient } from '@cosmjs/tendermint-rpc'; +import { + HttpBatchClient, + HttpBatchClientOptions, + RpcClient, + Tendermint34Client, + TendermintClient +} from '@cosmjs/tendermint-rpc'; import _ from 'lodash'; import Long from 'long'; @@ -161,6 +167,31 @@ export class SigningArchwayClient extends SigningCosmWasmClient implements IArch return SigningArchwayClient.createWithSigner(tmClient, signer, options); } + /** + * Creates an instance by connecting to the given Tendermint RPC endpoint using an {@link HttpBatchClient} to batch + * multiple requests and reduce queries to the server. + * + * @param endpoint - String URL of the RPC endpoint to connect or an {@link HttpEndpoint} object. + * @param signer - The transaction signer configuration. + * @param options - Options for the signing client. + * @param batchClientOptions - Optional configuration to control how the {@link HttpBatchClient} will batch requests. + * @returns A {@link SigningArchwayClient} connected to the endpoint. + * + * @remarks This factory method doesn't support WebSocket endpoints. + * + * @see {@link SigningArchwayClient.createWithSigner} if you need Tendermint 0.37 support. + */ + public static async connectWithSignerAndBatchClient( + endpoint: string | HttpEndpoint, + signer: OfflineSigner, + options?: SigningArchwayClientOptions, + batchClientOptions?: Partial + ): Promise { + const rpcClient: RpcClient = new HttpBatchClient(endpoint, batchClientOptions); + const tmClient = await Tendermint34Client.create(rpcClient); + return SigningArchwayClient.createWithSigner(tmClient, signer, options); + } + /** * Creates an instance from a manually created Tendermint client. *