mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Merge pull request #822 from cosmos/789-tendermint-33-client
Rename Tendermint 0.33 client and reorganise
This commit is contained in:
commit
e38d797184
11
CHANGELOG.md
11
CHANGELOG.md
@ -11,13 +11,22 @@ and this project adheres to
|
||||
- @cosmjs/tendermint-rpc: `Tendermint34Client.blockSearch` and
|
||||
`Tendermint34Client.blockSearchAll` were added to allow searching blocks in
|
||||
Tendermint 0.34.9+ backends.
|
||||
- @cosmjs/tendermint-rpc: `Tendermint33Client` has been added to provide support
|
||||
for Tendermint v0.33.
|
||||
- @cosmjs/tendermint-rpc: Exports relating to `Tendermint33Client` are now
|
||||
available under `tendermint33`.
|
||||
|
||||
### Changes
|
||||
### Changed
|
||||
|
||||
- @cosmjs/tendermint-rpc: Make `tendermint34.Header.lastBlockId` and
|
||||
`tendermint34.Block.lastCommit` optional to better handle the case of height 1
|
||||
where there is no previous block.
|
||||
|
||||
### Removed
|
||||
|
||||
- @cosmjs/tendermint-rpc: `Client` has been removed. Please use
|
||||
`Tendermint33Client` or `Tendermint34Client`, depending on your needs.
|
||||
|
||||
### Fixed
|
||||
|
||||
- @cosmjs/socket: Upgrade dependency "ws" to version 7 to avoid potential
|
||||
|
@ -5,10 +5,24 @@ export {
|
||||
rawSecp256k1PubkeyToRawAddress,
|
||||
} from "./addresses";
|
||||
export {
|
||||
adaptor33,
|
||||
adaptor34,
|
||||
Adaptor,
|
||||
Client,
|
||||
DateTime,
|
||||
ReadonlyDateWithNanoseconds,
|
||||
fromRfc3339WithNanoseconds,
|
||||
fromSeconds,
|
||||
toRfc3339WithNanoseconds,
|
||||
toSeconds,
|
||||
} from "./dates";
|
||||
export { HttpClient, WebsocketClient } from "./rpcclients"; // TODO: Why do we export those outside of this package?
|
||||
export {
|
||||
BlockIdFlag,
|
||||
CommitSignature,
|
||||
ValidatorEd25519Pubkey,
|
||||
ValidatorSecp256k1Pubkey,
|
||||
ValidatorPubkey,
|
||||
} from "./types";
|
||||
export * as tendermint33 from "./tendermint33";
|
||||
export {
|
||||
Tendermint33Client,
|
||||
AbciInfoResponse,
|
||||
AbciQueryResponse,
|
||||
Attribute,
|
||||
@ -75,22 +89,6 @@ export {
|
||||
TxSearchRequest,
|
||||
ValidatorsRequest,
|
||||
ValidatorsParams,
|
||||
} from "./legacy";
|
||||
export {
|
||||
DateTime,
|
||||
ReadonlyDateWithNanoseconds,
|
||||
fromRfc3339WithNanoseconds,
|
||||
fromSeconds,
|
||||
toRfc3339WithNanoseconds,
|
||||
toSeconds,
|
||||
} from "./dates";
|
||||
export { HttpClient, WebsocketClient } from "./rpcclients"; // TODO: Why do we export those outside of this package?
|
||||
export {
|
||||
BlockIdFlag,
|
||||
CommitSignature,
|
||||
ValidatorEd25519Pubkey,
|
||||
ValidatorSecp256k1Pubkey,
|
||||
ValidatorPubkey,
|
||||
} from "./types";
|
||||
} from "./tendermint33";
|
||||
export * as tendermint34 from "./tendermint34";
|
||||
export { Tendermint34Client } from "./tendermint34";
|
||||
|
@ -1,42 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Adaptor } from "../adaptor";
|
||||
import { v0_33 } from "./v0-33";
|
||||
|
||||
/**
|
||||
* Adaptor for Tendermint 0.33.
|
||||
*
|
||||
* Use this to skip auto-detection:
|
||||
*
|
||||
* ```
|
||||
* import { adaptor33, Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
* // ...
|
||||
* const client = await TendermintClient.connect(url, adaptor33);
|
||||
* ```
|
||||
*/
|
||||
export const adaptor33 = v0_33;
|
||||
|
||||
/**
|
||||
* Adaptor for Tendermint 0.34.
|
||||
*
|
||||
* Use this to skip auto-detection:
|
||||
*
|
||||
* ```
|
||||
* import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
* // ...
|
||||
* const client = await TendermintClient.connect(url, adaptor34);
|
||||
* ```
|
||||
*/
|
||||
export const adaptor34 = v0_33; // With this alias we can swap out the implementation without affecting caller code.
|
||||
|
||||
/**
|
||||
* Returns an Adaptor implementation for a given tendermint version.
|
||||
* Throws when version is not supported.
|
||||
*
|
||||
* @param version full Tendermint version string, e.g. "0.20.1"
|
||||
*/
|
||||
export function adaptorForVersion(_version: string): Adaptor {
|
||||
// Note: In some cases, Tendermint 0.34 returns an empty version value.
|
||||
// This supports 0.33 and 0.34 now, no matter which version you provide.
|
||||
// Very soon this function becomes obsolete (https://github.com/cosmos/cosmjs/issues/789).
|
||||
return v0_33;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Adaptor } from "../../adaptor";
|
||||
import { hashBlock, hashTx } from "../../hasher";
|
||||
import { Params } from "./requests";
|
||||
import { Responses } from "./responses";
|
||||
|
||||
export const v0_33: Adaptor = {
|
||||
params: Params,
|
||||
responses: Responses,
|
||||
hashTx: hashTx,
|
||||
hashBlock: hashBlock,
|
||||
};
|
13
packages/tendermint-rpc/src/tendermint33/adaptor/index.ts
Normal file
13
packages/tendermint-rpc/src/tendermint33/adaptor/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { hashBlock, hashTx } from "../hasher";
|
||||
import { Params } from "./requests";
|
||||
import { Responses } from "./responses";
|
||||
import { Adaptor } from "./types";
|
||||
|
||||
export { Decoder, Encoder, Params, Responses } from "./types";
|
||||
|
||||
export const adaptor33: Adaptor = {
|
||||
params: Params,
|
||||
responses: Responses,
|
||||
hashTx: hashTx,
|
||||
hashBlock: hashBlock,
|
||||
};
|
@ -2,9 +2,9 @@
|
||||
import { toBase64, toHex } from "@cosmjs/encoding";
|
||||
import { JsonRpcRequest } from "@cosmjs/json-rpc";
|
||||
|
||||
import { createJsonRpcRequest } from "../../../jsonrpc";
|
||||
import { assertNotEmpty, Integer, may } from "../../encodings";
|
||||
import * as requests from "../../requests";
|
||||
import { createJsonRpcRequest } from "../../jsonrpc";
|
||||
import { assertNotEmpty, Integer, may } from "../encodings";
|
||||
import * as requests from "../requests";
|
||||
|
||||
interface HeightParam {
|
||||
readonly height?: number;
|
@ -3,9 +3,9 @@ import { fromBase64, fromHex } from "@cosmjs/encoding";
|
||||
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { fromRfc3339WithNanoseconds } from "../../../dates";
|
||||
import { SubscriptionEvent } from "../../../rpcclients";
|
||||
import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../../types";
|
||||
import { fromRfc3339WithNanoseconds } from "../../dates";
|
||||
import { SubscriptionEvent } from "../../rpcclients";
|
||||
import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../types";
|
||||
import {
|
||||
assertArray,
|
||||
assertBoolean,
|
||||
@ -18,9 +18,9 @@ import {
|
||||
Integer,
|
||||
may,
|
||||
optional,
|
||||
} from "../../encodings";
|
||||
import { hashTx } from "../../hasher";
|
||||
import * as responses from "../../responses";
|
||||
} from "../encodings";
|
||||
import { hashTx } from "../hasher";
|
||||
import * as responses from "../responses";
|
||||
|
||||
interface AbciInfoResult {
|
||||
readonly response: RpcAbciInfoResponse;
|
@ -1,8 +1,8 @@
|
||||
import { JsonRpcRequest, JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
||||
|
||||
import { SubscriptionEvent } from "../rpcclients";
|
||||
import * as requests from "./requests";
|
||||
import * as responses from "./responses";
|
||||
import { SubscriptionEvent } from "../../rpcclients";
|
||||
import * as requests from "../requests";
|
||||
import * as responses from "../responses";
|
||||
|
||||
export interface Adaptor {
|
||||
readonly params: Params;
|
@ -1,6 +1,7 @@
|
||||
export { adaptor33, adaptor34 } from "./adaptors";
|
||||
export { Adaptor } from "./adaptor";
|
||||
export { Client } from "./client";
|
||||
// Note: all exports in this module are public available via
|
||||
// `import { tendermint33 } from "@cosmjs/tendermint-rpc"`
|
||||
|
||||
export { Tendermint33Client } from "./tendermint33client";
|
||||
export {
|
||||
AbciInfoRequest,
|
||||
AbciQueryParams,
|
@ -16,17 +16,16 @@ import {
|
||||
tendermintInstances,
|
||||
tendermintSearchIndexUpdated,
|
||||
} from "../testutil.spec";
|
||||
import { Adaptor } from "./adaptor";
|
||||
import { adaptorForVersion } from "./adaptors";
|
||||
import { Client } from "./client";
|
||||
import { adaptor33 } from "./adaptor";
|
||||
import { buildQuery } from "./requests";
|
||||
import * as responses from "./responses";
|
||||
import { Tendermint33Client } from "./tendermint33client";
|
||||
|
||||
function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expected: ExpectedValues): void {
|
||||
function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues): void {
|
||||
describe("create", () => {
|
||||
it("can auto-discover Tendermint version and communicate", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory());
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
@ -34,7 +33,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can connect to Tendermint with known version", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
expect(await client.abciInfo()).toBeTruthy();
|
||||
client.disconnect();
|
||||
});
|
||||
@ -42,7 +41,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can get genesis", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const genesis = await client.genesis();
|
||||
expect(genesis).toBeTruthy();
|
||||
client.disconnect();
|
||||
@ -50,7 +49,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
@ -68,9 +67,9 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("gets the same tx hash from backend as calculated locally", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
const calculatedTxHash = adaptor.hashTx(tx);
|
||||
const calculatedTxHash = adaptor33.hashTx(tx);
|
||||
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
expect(response.hash).toEqual(calculatedTxHash);
|
||||
@ -80,7 +79,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can query the state", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const key = randomString();
|
||||
const value = randomString();
|
||||
@ -99,7 +98,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can get a commit", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const response = await client.commit(4);
|
||||
|
||||
expect(response).toBeTruthy();
|
||||
@ -114,7 +113,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can get validators", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const response = await client.validators({});
|
||||
|
||||
expect(response).toBeTruthy();
|
||||
@ -132,7 +131,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can get all validators", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const response = await client.validatorsAll();
|
||||
|
||||
expect(response).toBeTruthy();
|
||||
@ -150,7 +149,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can call a bunch of methods", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
expect(await client.block()).toBeTruthy();
|
||||
expect(await client.genesis()).toBeTruthy();
|
||||
@ -162,7 +161,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
describe("status", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const status = await client.status();
|
||||
|
||||
@ -192,7 +191,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
describe("blockResults", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const height = 3;
|
||||
const results = await client.blockResults(height);
|
||||
@ -208,7 +207,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
describe("blockchain", () => {
|
||||
it("returns latest in descending order by default", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
// Run in parallel to increase chance there is no block between the calls
|
||||
const [status, blockchain] = await Promise.all([client.status(), client.blockchain()]);
|
||||
@ -225,7 +224,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can limit by maxHeight", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const height = (await client.status()).syncInfo.latestBlockHeight;
|
||||
const blockchain = await client.blockchain(undefined, height - 1);
|
||||
@ -239,7 +238,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("works with maxHeight in the future", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const height = (await client.status()).syncInfo.latestBlockHeight;
|
||||
const blockchain = await client.blockchain(undefined, height + 20);
|
||||
@ -253,7 +252,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can limit by minHeight and maxHeight", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const height = (await client.status()).syncInfo.latestBlockHeight;
|
||||
const blockchain = await client.blockchain(height - 2, height - 1);
|
||||
@ -267,7 +266,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("contains all the info", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const height = (await client.status()).syncInfo.latestBlockHeight;
|
||||
const blockchain = await client.blockchain(height - 1, height - 1);
|
||||
@ -297,7 +296,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
describe("tx", () => {
|
||||
it("can query a tx properly", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const find = randomString();
|
||||
const me = randomString();
|
||||
@ -354,7 +353,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
beforeAll(async () => {
|
||||
if (tendermintEnabled()) {
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
// eslint-disable-next-line no-inner-declarations
|
||||
async function sendTx(): Promise<void> {
|
||||
@ -380,7 +379,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can paginate over txSearch results", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const query = buildQuery({ tags: [{ key: "app.key", value: key }] });
|
||||
|
||||
@ -399,7 +398,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
|
||||
it("can get all search results in one call", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
|
||||
const query = buildQuery({ tags: [{ key: "app.key", value: key }] });
|
||||
|
||||
@ -416,7 +415,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
});
|
||||
}
|
||||
|
||||
function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expected: ExpectedValues): void {
|
||||
function websocketTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues): void {
|
||||
it("can subscribe to block header events", (done) => {
|
||||
pendingWithoutTendermint();
|
||||
|
||||
@ -424,7 +423,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
|
||||
(async () => {
|
||||
const events: responses.NewBlockHeaderEvent[] = [];
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const stream = client.subscribeNewBlockHeader();
|
||||
expect(stream).toBeTruthy();
|
||||
const subscription = stream.subscribe({
|
||||
@ -482,7 +481,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
const transactionData2 = buildKvTx(randomString(), randomString());
|
||||
|
||||
const events: responses.NewBlockEvent[] = [];
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const stream = client.subscribeNewBlock();
|
||||
const subscription = stream.subscribe({
|
||||
next: (event) => {
|
||||
@ -538,7 +537,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
pendingWithoutTendermint();
|
||||
|
||||
const events: responses.TxEvent[] = [];
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const stream = client.subscribeTx();
|
||||
const subscription = stream.subscribe({
|
||||
next: (event) => {
|
||||
@ -582,7 +581,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
const transactionData2 = buildKvTx(randomString(), randomString());
|
||||
|
||||
const events: responses.TxEvent[] = [];
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const query = buildQuery({ tags: [{ key: "app.creator", value: expected.appCreator }] });
|
||||
const stream = client.subscribeTx(query);
|
||||
expect(stream).toBeTruthy();
|
||||
@ -620,7 +619,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
it("can unsubscribe and re-subscribe to the same stream", async () => {
|
||||
pendingWithoutTendermint();
|
||||
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const stream = client.subscribeNewBlockHeader();
|
||||
|
||||
const event1 = await firstEvent(stream);
|
||||
@ -653,7 +652,7 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
it("can subscribe twice", async () => {
|
||||
pendingWithoutTendermint();
|
||||
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const stream1 = client.subscribeNewBlockHeader();
|
||||
const stream2 = client.subscribeNewBlockHeader();
|
||||
|
||||
@ -665,48 +664,46 @@ function websocketTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expec
|
||||
});
|
||||
}
|
||||
|
||||
for (const { url, version, expected } of tendermintInstances) {
|
||||
describe(`Client ${version}`, () => {
|
||||
it("can connect to a given url", async () => {
|
||||
pendingWithoutTendermint();
|
||||
describe(`Tendermint33Client`, () => {
|
||||
const { url, expected } = tendermintInstances[0];
|
||||
|
||||
// default connection
|
||||
{
|
||||
const client = await Client.connect(url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
it("can connect to a given url", async () => {
|
||||
pendingWithoutTendermint();
|
||||
|
||||
// http connection
|
||||
{
|
||||
const client = await Client.connect("http://" + url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
// default connection
|
||||
{
|
||||
const client = await Tendermint33Client.connect(url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
// ws connection
|
||||
{
|
||||
const client = await Client.connect("ws://" + url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
});
|
||||
// http connection
|
||||
{
|
||||
const client = await Tendermint33Client.connect("http://" + url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
describe("With HttpClient", () => {
|
||||
const adaptor = adaptorForVersion(version);
|
||||
defaultTestSuite(() => new HttpClient(url), adaptor, expected);
|
||||
});
|
||||
|
||||
describe("With WebsocketClient", () => {
|
||||
// don't print out WebSocket errors if marked pending
|
||||
const onError = process.env.TENDERMINT_ENABLED ? console.error : () => 0;
|
||||
const factory = (): WebsocketClient => new WebsocketClient(url, onError);
|
||||
const adaptor = adaptorForVersion(version);
|
||||
defaultTestSuite(factory, adaptor, expected);
|
||||
websocketTestSuite(factory, adaptor, expected);
|
||||
});
|
||||
// ws connection
|
||||
{
|
||||
const client = await Tendermint33Client.connect("ws://" + url);
|
||||
const info = await client.abciInfo();
|
||||
expect(info).toBeTruthy();
|
||||
client.disconnect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe("With HttpClient", () => {
|
||||
defaultTestSuite(() => new HttpClient(url), expected);
|
||||
});
|
||||
|
||||
describe("With WebsocketClient", () => {
|
||||
// don't print out WebSocket errors if marked pending
|
||||
const onError = process.env.TENDERMINT_ENABLED ? console.error : () => 0;
|
||||
const factory = (): WebsocketClient => new WebsocketClient(url, onError);
|
||||
defaultTestSuite(factory, expected);
|
||||
websocketTestSuite(factory, expected);
|
||||
});
|
||||
});
|
@ -9,38 +9,32 @@ import {
|
||||
SubscriptionEvent,
|
||||
WebsocketClient,
|
||||
} from "../rpcclients";
|
||||
import { Adaptor, Decoder, Encoder, Params, Responses } from "./adaptor";
|
||||
import { adaptorForVersion } from "./adaptors";
|
||||
import { adaptor33, Decoder, Encoder, Params, Responses } from "./adaptor";
|
||||
import * as requests from "./requests";
|
||||
import * as responses from "./responses";
|
||||
|
||||
/** @deprecated Use Tendermint34Client */
|
||||
export class Client {
|
||||
export class Tendermint33Client {
|
||||
/**
|
||||
* Creates a new Tendermint client for the given endpoint.
|
||||
*
|
||||
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
||||
*
|
||||
* If the adaptor is not set an auto-detection is attempted.
|
||||
*/
|
||||
public static async connect(url: string, adaptor?: Adaptor): Promise<Client> {
|
||||
public static async connect(url: string): Promise<Tendermint33Client> {
|
||||
const useHttp = url.startsWith("http://") || url.startsWith("https://");
|
||||
const rpcClient = useHttp ? new HttpClient(url) : new WebsocketClient(url);
|
||||
return Client.create(rpcClient, adaptor);
|
||||
return Tendermint33Client.create(rpcClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Tendermint client given an RPC client.
|
||||
*
|
||||
* If the adaptor is not set an auto-detection is attempted.
|
||||
*/
|
||||
public static async create(rpcClient: RpcClient, adaptor?: Adaptor): Promise<Client> {
|
||||
public static async create(rpcClient: RpcClient): Promise<Tendermint33Client> {
|
||||
// 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 Client(rpcClient, adaptor || adaptorForVersion(version));
|
||||
const _version = await this.detectVersion(rpcClient);
|
||||
return new Tendermint33Client(rpcClient);
|
||||
}
|
||||
|
||||
private static async detectVersion(client: RpcClient): Promise<string> {
|
||||
@ -64,12 +58,12 @@ export class Client {
|
||||
private readonly r: Responses;
|
||||
|
||||
/**
|
||||
* Use `Client.connect` or `Client.create` to create an instance.
|
||||
* Use `Tendermint33Client.connect` or `Tendermint33Client.create` to create an instance.
|
||||
*/
|
||||
private constructor(client: RpcClient, adaptor: Adaptor) {
|
||||
private constructor(client: RpcClient) {
|
||||
this.client = client;
|
||||
this.p = adaptor.params;
|
||||
this.r = adaptor.responses;
|
||||
this.p = adaptor33.params;
|
||||
this.r = adaptor33.responses;
|
||||
}
|
||||
|
||||
public disconnect(): void {
|
13
packages/tendermint-rpc/src/tendermint34/adaptor/index.ts
Normal file
13
packages/tendermint-rpc/src/tendermint34/adaptor/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { hashBlock, hashTx } from "../hasher";
|
||||
import { Params } from "./requests";
|
||||
import { Responses } from "./responses";
|
||||
import { Adaptor } from "./types";
|
||||
|
||||
export { Decoder, Encoder, Params, Responses } from "./types";
|
||||
|
||||
export const adaptor34: Adaptor = {
|
||||
params: Params,
|
||||
responses: Responses,
|
||||
hashTx: hashTx,
|
||||
hashBlock: hashBlock,
|
||||
};
|
@ -2,9 +2,9 @@
|
||||
import { toBase64, toHex } from "@cosmjs/encoding";
|
||||
import { JsonRpcRequest } from "@cosmjs/json-rpc";
|
||||
|
||||
import { createJsonRpcRequest } from "../../../jsonrpc";
|
||||
import { assertNotEmpty, Integer, may } from "../../encodings";
|
||||
import * as requests from "../../requests";
|
||||
import { createJsonRpcRequest } from "../../jsonrpc";
|
||||
import { assertNotEmpty, Integer, may } from "../encodings";
|
||||
import * as requests from "../requests";
|
||||
|
||||
interface HeightParam {
|
||||
readonly height?: number;
|
@ -3,9 +3,9 @@ import { fromBase64, fromHex } from "@cosmjs/encoding";
|
||||
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { DateWithNanoseconds, fromRfc3339WithNanoseconds } from "../../../dates";
|
||||
import { SubscriptionEvent } from "../../../rpcclients";
|
||||
import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../../types";
|
||||
import { DateWithNanoseconds, fromRfc3339WithNanoseconds } from "../../dates";
|
||||
import { SubscriptionEvent } from "../../rpcclients";
|
||||
import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../types";
|
||||
import {
|
||||
assertArray,
|
||||
assertBoolean,
|
||||
@ -18,9 +18,9 @@ import {
|
||||
Integer,
|
||||
may,
|
||||
optional,
|
||||
} from "../../encodings";
|
||||
import { hashTx } from "../../hasher";
|
||||
import * as responses from "../../responses";
|
||||
} from "../encodings";
|
||||
import { hashTx } from "../hasher";
|
||||
import * as responses from "../responses";
|
||||
|
||||
interface AbciInfoResult {
|
||||
readonly response: RpcAbciInfoResponse;
|
@ -1,8 +1,8 @@
|
||||
import { JsonRpcRequest, JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
||||
|
||||
import { SubscriptionEvent } from "../rpcclients";
|
||||
import * as requests from "./requests";
|
||||
import * as responses from "./responses";
|
||||
import { SubscriptionEvent } from "../../rpcclients";
|
||||
import * as requests from "../requests";
|
||||
import * as responses from "../responses";
|
||||
|
||||
export interface Adaptor {
|
||||
readonly params: Params;
|
@ -1,2 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
export { v0_34 as adaptor34 } from "./v0-34";
|
@ -1,12 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Adaptor } from "../../adaptor";
|
||||
import { hashBlock, hashTx } from "../../hasher";
|
||||
import { Params } from "./requests";
|
||||
import { Responses } from "./responses";
|
||||
|
||||
export const v0_34: Adaptor = {
|
||||
params: Params,
|
||||
responses: Responses,
|
||||
hashTx: hashTx,
|
||||
hashBlock: hashBlock,
|
||||
};
|
@ -16,7 +16,7 @@ import {
|
||||
tendermintInstances,
|
||||
tendermintSearchIndexUpdated,
|
||||
} from "../testutil.spec";
|
||||
import { adaptor34 } from "./adaptors";
|
||||
import { adaptor34 } from "./adaptor";
|
||||
import { buildQuery } from "./requests";
|
||||
import * as responses from "./responses";
|
||||
import { Tendermint34Client } from "./tendermint34client";
|
||||
|
@ -9,8 +9,7 @@ import {
|
||||
SubscriptionEvent,
|
||||
WebsocketClient,
|
||||
} from "../rpcclients";
|
||||
import { Decoder, Encoder, Params, Responses } from "./adaptor";
|
||||
import { adaptor34 } from "./adaptors";
|
||||
import { adaptor34, Decoder, Encoder, Params, Responses } from "./adaptor";
|
||||
import * as requests from "./requests";
|
||||
import * as responses from "./responses";
|
||||
|
||||
@ -19,8 +18,6 @@ export class Tendermint34Client {
|
||||
* Creates a new Tendermint client for the given endpoint.
|
||||
*
|
||||
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
||||
*
|
||||
* If the adaptor is not set an auto-detection is attempted.
|
||||
*/
|
||||
public static async connect(url: string): Promise<Tendermint34Client> {
|
||||
const useHttp = url.startsWith("http://") || url.startsWith("https://");
|
||||
@ -30,8 +27,6 @@ export class Tendermint34Client {
|
||||
|
||||
/**
|
||||
* Creates a new Tendermint client given an RPC client.
|
||||
*
|
||||
* If the adaptor is not set an auto-detection is attempted.
|
||||
*/
|
||||
public static async create(rpcClient: RpcClient): Promise<Tendermint34Client> {
|
||||
// For some very strange reason I don't understand, tests start to fail on some systems
|
||||
@ -63,7 +58,7 @@ export class Tendermint34Client {
|
||||
private readonly r: Responses;
|
||||
|
||||
/**
|
||||
* Use `Client.connect` or `Client.create` to create an instance.
|
||||
* Use `Tendermint34Client.connect` or `Tendermint34Client.create` to create an instance.
|
||||
*/
|
||||
private constructor(client: RpcClient) {
|
||||
this.client = client;
|
||||
|
Loading…
x
Reference in New Issue
Block a user