Organize adaptor exports

This commit is contained in:
Simon Warta 2020-11-18 14:47:59 +01:00
parent e4d1fd1425
commit bfd9ebeeed
20 changed files with 127 additions and 62 deletions

View File

@ -20,6 +20,8 @@
optional adaptor.
- @cosmjs/tendermint-rpc: Add an optional adaptor argument to `Client.connect`
which allows skipping the auto-detection.
- @cosmjs/tendermint-rpc: Remove export `v0_33` in favour of `adaptor33` and
`adaptor34`. Export the `Adaptor` type.
## 0.23.1 (2020-10-27)

View File

@ -1,26 +0,0 @@
/* eslint-disable @typescript-eslint/naming-convention */
// This module exposes translators for multiple tendermint versions
// Pick a version that matches the server to properly encode the data types
import { Adaptor } from "./adaptor";
import { v0_33 } from "./v0-33";
const hashes = {
v0_34: [
"ca2c9df", // v0.34.0-rc6
"", // See https://github.com/cosmos/cosmos-sdk/issues/7963
],
};
/**
* 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 {
if (version.startsWith("0.33.") || version.startsWith("0.34.") || hashes.v0_34.includes(version)) {
return v0_33;
} else {
throw new Error(`Unsupported tendermint version: ${version}`);
}
}

View File

@ -0,0 +1,50 @@
/* 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.
const hashes = {
v0_34: [
"ca2c9df", // v0.34.0-rc6
"", // See https://github.com/cosmos/cosmos-sdk/issues/7963
],
};
/**
* 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 {
if (version.startsWith("0.33.") || version.startsWith("0.34.") || hashes.v0_34.includes(version)) {
return v0_33;
} else {
throw new Error(`Unsupported tendermint version: ${version}`);
}
}

View File

@ -1,8 +1,8 @@
import { fromBase64, fromHex } from "@cosmjs/encoding";
import { ReadonlyDate } from "readonly-date";
import { ReadonlyDateWithNanoseconds } from "../responses";
import { TxBytes } from "../types";
import { ReadonlyDateWithNanoseconds } from "../../responses";
import { TxBytes } from "../../types";
import { hashBlock, hashTx } from "./hasher";
describe("Hasher", () => {

View File

@ -1,8 +1,15 @@
import { Sha256 } from "@cosmjs/crypto";
import { encodeBlockId, encodeBytes, encodeInt, encodeString, encodeTime, encodeVersion } from "../encodings";
import { Header } from "../responses";
import { BlockHash, TxBytes, TxHash } from "../types";
import {
encodeBlockId,
encodeBytes,
encodeInt,
encodeString,
encodeTime,
encodeVersion,
} from "../../encodings";
import { Header } from "../../responses";
import { BlockHash, TxBytes, TxHash } from "../../types";
// hash is sha256
// https://github.com/tendermint/tendermint/blob/master/UPGRADING.md#v0260

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Adaptor } from "../adaptor";
import { Adaptor } from "../../adaptor";
import { hashBlock, hashTx } from "./hasher";
import { Params } from "./requests";
import { Responses } from "./responses";

View File

@ -2,9 +2,17 @@
import { toHex } from "@cosmjs/encoding";
import { JsonRpcRequest } from "@cosmjs/json-rpc";
import { assertNotEmpty, Base64, Base64String, HexString, Integer, IntegerString, may } from "../encodings";
import { createJsonRpcRequest } from "../jsonrpc";
import * as requests from "../requests";
import {
assertNotEmpty,
Base64,
Base64String,
HexString,
Integer,
IntegerString,
may,
} from "../../encodings";
import { createJsonRpcRequest } from "../../jsonrpc";
import * as requests from "../../requests";
interface HeightParam {
readonly height?: number;

View File

@ -20,10 +20,10 @@ import {
IntegerString,
may,
optional,
} from "../encodings";
import * as responses from "../responses";
import { SubscriptionEvent } from "../rpcclients";
import { IpPortString, TxBytes, TxHash, ValidatorPubkey, ValidatorSignature } from "../types";
} from "../../encodings";
import * as responses from "../../responses";
import { SubscriptionEvent } from "../../rpcclients";
import { IpPortString, TxBytes, TxHash, ValidatorPubkey, ValidatorSignature } from "../../types";
import { hashTx } from "./hasher";
interface AbciInfoResult {

View File

@ -6,7 +6,7 @@ import { ReadonlyDate } from "readonly-date";
import { Stream } from "xstream";
import { Adaptor } from "./adaptor";
import { adaptorForVersion } from "./adaptorforversion";
import { adaptorForVersion } from "./adaptors";
import { Client } from "./client";
import { ExpectedValues, tendermintInstances } from "./config.spec";
import { buildQuery } from "./requests";

View File

@ -1,7 +1,7 @@
import { Stream } from "xstream";
import { Adaptor, Decoder, Encoder, Params, Responses } from "./adaptor";
import { adaptorForVersion } from "./adaptorforversion";
import { adaptorForVersion } from "./adaptors";
import { createJsonRpcRequest } from "./jsonrpc";
import * as requests from "./requests";
import * as responses from "./responses";

View File

@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
// exported to access version-specific hashing
export { v0_33 } from "./v0-33";
export { Adaptor } from "./adaptor";
export { adaptor33, adaptor34 } from "./adaptors";
export { Client } from "./client";
export {
AbciInfoRequest,

View File

@ -1,8 +0,0 @@
import { Adaptor } from "./adaptor";
/**
* 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 declare function adaptorForVersion(version: string): Adaptor;

View File

@ -0,0 +1,32 @@
import { Adaptor } from "../adaptor";
/**
* 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 declare const adaptor33: Adaptor;
/**
* 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 declare const adaptor34: Adaptor;
/**
* 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 declare function adaptorForVersion(version: string): Adaptor;

View File

@ -1,4 +1,4 @@
import { Header } from "../responses";
import { BlockHash, TxBytes, TxHash } from "../types";
import { Header } from "../../responses";
import { BlockHash, TxBytes, TxHash } from "../../types";
export declare function hashTx(tx: TxBytes): TxHash;
export declare function hashBlock(header: Header): BlockHash;

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,2 @@
import { Adaptor } from "../../adaptor";
export declare const v0_33: Adaptor;

View File

@ -1,5 +1,5 @@
import { JsonRpcRequest } from "@cosmjs/json-rpc";
import * as requests from "../requests";
import * as requests from "../../requests";
export declare class Params {
static encodeAbciInfo(req: requests.AbciInfoRequest): JsonRpcRequest;
static encodeAbciQuery(req: requests.AbciQueryRequest): JsonRpcRequest;

View File

@ -1,7 +1,7 @@
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
import { Base64String } from "../encodings";
import * as responses from "../responses";
import { SubscriptionEvent } from "../rpcclients";
import { Base64String } from "../../encodings";
import * as responses from "../../responses";
import { SubscriptionEvent } from "../../rpcclients";
export interface RpcProofOp {
readonly type: string;
readonly key: Base64String;

View File

@ -1,4 +1,5 @@
export { v0_33 } from "./v0-33";
export { Adaptor } from "./adaptor";
export { adaptor33, adaptor34 } from "./adaptors";
export { Client } from "./client";
export {
AbciInfoRequest,

View File

@ -1,2 +0,0 @@
import { Adaptor } from "../adaptor";
export declare const v0_33: Adaptor;