Use symbols from tendermint34 folder

This commit is contained in:
Simon Warta 2021-11-22 21:13:43 +01:00
parent fe07180431
commit 95e6156d3b
9 changed files with 1 additions and 928 deletions

View File

@ -87,6 +87,6 @@ export {
TxSearchRequest,
ValidatorsRequest,
ValidatorsParams,
} from "./tendermint33";
} from "./tendermint34";
export * as tendermint34 from "./tendermint34";
export { Tendermint34Client } from "./tendermint34";

View File

@ -1,90 +0,0 @@
import { ReadonlyDate } from "readonly-date";
import { encodeBlockId, encodeBytes, encodeInt, encodeString, encodeTime, encodeVersion } from "./encodings";
describe("encodings", () => {
describe("encodeString", () => {
it("works", () => {
expect(encodeString("")).toEqual(Uint8Array.from([0]));
const str = "hello iov";
expect(encodeString(str)).toEqual(
Uint8Array.from([str.length, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x69, 0x6f, 0x76]),
);
});
});
describe("encodeInt", () => {
it("works", () => {
expect(encodeInt(0)).toEqual(Uint8Array.from([0]));
expect(encodeInt(1)).toEqual(Uint8Array.from([1]));
expect(encodeInt(127)).toEqual(Uint8Array.from([127]));
expect(encodeInt(128)).toEqual(Uint8Array.from([128, 1]));
expect(encodeInt(255)).toEqual(Uint8Array.from([255, 1]));
expect(encodeInt(256)).toEqual(Uint8Array.from([128, 2]));
});
});
describe("encodeTime", () => {
it("works", () => {
const readonlyDateWithNanoseconds = new ReadonlyDate(1464109200);
(readonlyDateWithNanoseconds as any).nanoseconds = 666666;
expect(encodeTime(readonlyDateWithNanoseconds)).toEqual(
Uint8Array.from([0x08, 173, 174, 89, 0x10, 170, 220, 215, 95]),
);
});
});
describe("encodeBytes", () => {
it("works", () => {
expect(encodeBytes(Uint8Array.from([]))).toEqual(Uint8Array.from([]));
const uint8Array = Uint8Array.from([1, 2, 3, 4, 5, 6, 7]);
expect(encodeBytes(uint8Array)).toEqual(Uint8Array.from([uint8Array.length, 1, 2, 3, 4, 5, 6, 7]));
});
});
describe("encodeVersion", () => {
it("works", () => {
const version = {
block: 666666,
app: 200,
};
expect(encodeVersion(version)).toEqual(Uint8Array.from([0x08, 170, 216, 40, 0x10, 200, 1]));
});
});
describe("encodeBlockId", () => {
it("works", () => {
const blockId = {
hash: Uint8Array.from([1, 2, 3, 4, 5, 6, 7]),
parts: {
total: 88,
hash: Uint8Array.from([8, 9, 10, 11, 12]),
},
};
expect(encodeBlockId(blockId)).toEqual(
Uint8Array.from([
0x0a,
blockId.hash.length,
1,
2,
3,
4,
5,
6,
7,
0x12,
9,
0x08,
88,
0x12,
5,
8,
9,
10,
11,
12,
]),
);
});
});
});

View File

@ -1,57 +0,0 @@
import { toUtf8 } from "@cosmjs/encoding";
import { ReadonlyDateWithNanoseconds } from "../dates";
import { BlockId, Version } from "./responses";
// Encodings needed for hashing block headers
// Several of these functions are inspired by https://github.com/nomic-io/js-tendermint/blob/tendermint-0.30/src/
// See https://github.com/tendermint/go-amino/blob/v0.15.0/encoder.go#L193-L195
export function encodeString(s: string): Uint8Array {
const utf8 = toUtf8(s);
return Uint8Array.from([utf8.length, ...utf8]);
}
// See https://github.com/tendermint/go-amino/blob/v0.15.0/encoder.go#L79-L87
export function encodeInt(n: number): Uint8Array {
// eslint-disable-next-line no-bitwise
return n >= 0x80 ? Uint8Array.from([(n & 0xff) | 0x80, ...encodeInt(n >> 7)]) : Uint8Array.from([n & 0xff]);
}
// See https://github.com/tendermint/go-amino/blob/v0.15.0/encoder.go#L134-L178
export function encodeTime(time: ReadonlyDateWithNanoseconds): Uint8Array {
const milliseconds = time.getTime();
const seconds = Math.floor(milliseconds / 1000);
const secondsArray = seconds ? [0x08, ...encodeInt(seconds)] : new Uint8Array();
const nanoseconds = (time.nanoseconds || 0) + (milliseconds % 1000) * 1e6;
const nanosecondsArray = nanoseconds ? [0x10, ...encodeInt(nanoseconds)] : new Uint8Array();
return Uint8Array.from([...secondsArray, ...nanosecondsArray]);
}
// See https://github.com/tendermint/go-amino/blob/v0.15.0/encoder.go#L180-L187
export function encodeBytes(bytes: Uint8Array): Uint8Array {
// Since we're only dealing with short byte arrays we don't need a full VarBuffer implementation yet
if (bytes.length >= 0x80) throw new Error("Not implemented for byte arrays of length 128 or more");
return bytes.length ? Uint8Array.from([bytes.length, ...bytes]) : new Uint8Array();
}
export function encodeVersion(version: Version): Uint8Array {
const blockArray = version.block ? Uint8Array.from([0x08, ...encodeInt(version.block)]) : new Uint8Array();
const appArray = version.app ? Uint8Array.from([0x10, ...encodeInt(version.app)]) : new Uint8Array();
return Uint8Array.from([...blockArray, ...appArray]);
}
export function encodeBlockId(blockId: BlockId): Uint8Array {
return Uint8Array.from([
0x0a,
blockId.hash.length,
...blockId.hash,
0x12,
blockId.parts.hash.length + 4,
0x08,
blockId.parts.total,
0x12,
blockId.parts.hash.length,
...blockId.parts.hash,
]);
}

View File

@ -1,83 +0,0 @@
import { fromBase64, fromHex } from "@cosmjs/encoding";
import { ReadonlyDate } from "readonly-date";
import { ReadonlyDateWithNanoseconds } from "../dates";
import { hashBlock } from "./hasher";
describe("Hasher", () => {
it("creates block hash equal to local test for empty block", () => {
// This was taken from a result from /block of some random empty block
// curl "http://localhost:11133/block"
const blockId = fromHex("153C484DCBC33633F0616BC019388C93DEA94F7880627976F2BFE83749E062F7");
const time = new ReadonlyDate("2020-06-23T13:54:15.4638668Z");
(time as any).nanoseconds = 866800;
const blockData = {
version: {
block: 10,
app: 1,
},
chainId: "test-chain-2A5rwi",
height: 7795,
time: time as ReadonlyDateWithNanoseconds,
lastBlockId: {
hash: fromHex("1EC48444E64E7B96585BA518613612E52B976E3DA2F2222B9CD4D1602656C96F"),
parts: {
total: 1,
hash: fromHex("D4E6F1B0EE08D0438C9BB8455D7D3F2FC1883C32D66F7C69C4A0F093B073F6D2"),
},
},
lastCommitHash: fromHex("BA6A5EEA6687ACA8EE4FFE4F5D40EA073CB7397A5336309C3EC824805AF9723E"),
dataHash: fromHex(""),
validatorsHash: fromHex("0BEEBC6AB3B7D4FE21E22B609CD4AEC7E121A42C07604FF1827651F0173745EB"),
nextValidatorsHash: fromHex("0BEEBC6AB3B7D4FE21E22B609CD4AEC7E121A42C07604FF1827651F0173745EB"),
consensusHash: fromHex("048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F"),
appHash: fromHex("8801000000000000"),
lastResultsHash: fromHex(""),
evidenceHash: fromHex(""),
proposerAddress: fromHex("614F305502F65C01114F9B8711D9A0AB0AC369F4"),
};
expect(hashBlock(blockData)).toEqual(blockId);
});
it("creates block hash equal to local test for block with a transaction", () => {
// This was taken from a result from /block of some random block with a transaction
// curl "http://localhost:11133/block?height=13575"
const blockId = fromHex("FF2995AF1F38B9A584077E53B5E144778718FB86539A51886A2C55F730403373");
const time = new ReadonlyDate("2020-06-23T15:34:12.3232688Z");
(time as any).nanoseconds = 268800;
const blockData = {
version: {
block: 10,
app: 1,
},
chainId: "test-chain-2A5rwi",
height: 13575,
time: time as ReadonlyDateWithNanoseconds,
lastBlockId: {
hash: fromHex("046D5441FC4D008FCDBF9F3DD5DC25CF00883763E44CF4FAF3923FB5FEA42D8F"),
parts: {
total: 1,
hash: fromHex("02E4715343625093C717638EAC67FB3A4B24CCC8DA610E0CB324D705E68FEF7B"),
},
},
lastCommitHash: fromHex("AA2B807F3B0ACC866AB58D90C2D0FC70B6C860CFAC440590B4F590CDC178A207"),
dataHash: fromHex("56782879F526889734BA65375CD92A9152C7114B2C91B2D2AD8464FF69E884AA"),
validatorsHash: fromHex("0BEEBC6AB3B7D4FE21E22B609CD4AEC7E121A42C07604FF1827651F0173745EB"),
nextValidatorsHash: fromHex("0BEEBC6AB3B7D4FE21E22B609CD4AEC7E121A42C07604FF1827651F0173745EB"),
consensusHash: fromHex("048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F"),
appHash: fromHex("CC02000000000000"),
lastResultsHash: fromHex("6E340B9CFFB37A989CA544E6BB780A2C78901D3FB33738768511A30617AFA01D"),
evidenceHash: fromHex(""),
proposerAddress: fromHex("614F305502F65C01114F9B8711D9A0AB0AC369F4"),
};
expect(hashBlock(blockData)).toEqual(blockId);
});
});

View File

@ -1,61 +0,0 @@
import { Sha256 } from "@cosmjs/crypto";
import { encodeBlockId, encodeBytes, encodeInt, encodeString, encodeTime, encodeVersion } from "./encodings";
import { Header } from "./responses";
function getSplitPoint(n: number): number {
if (n < 1) throw new Error("Cannot split an empty tree");
const largestPowerOf2 = 2 ** Math.floor(Math.log2(n));
return largestPowerOf2 < n ? largestPowerOf2 : largestPowerOf2 / 2;
}
function hashLeaf(leaf: Uint8Array): Uint8Array {
const hash = new Sha256(Uint8Array.from([0]));
hash.update(leaf);
return hash.digest();
}
function hashInner(left: Uint8Array, right: Uint8Array): Uint8Array {
const hash = new Sha256(Uint8Array.from([1]));
hash.update(left);
hash.update(right);
return hash.digest();
}
// See https://github.com/tendermint/tendermint/blob/v0.31.8/docs/spec/blockchain/encoding.md#merkleroot
// Note: the hashes input may not actually be hashes, especially before a recursive call
function hashTree(hashes: readonly Uint8Array[]): Uint8Array {
switch (hashes.length) {
case 0:
throw new Error("Cannot hash empty tree");
case 1:
return hashLeaf(hashes[0]);
default: {
const slicePoint = getSplitPoint(hashes.length);
const left = hashTree(hashes.slice(0, slicePoint));
const right = hashTree(hashes.slice(slicePoint));
return hashInner(left, right);
}
}
}
export function hashBlock(header: Header): Uint8Array {
const encodedFields: readonly Uint8Array[] = [
encodeVersion(header.version),
encodeString(header.chainId),
encodeInt(header.height),
encodeTime(header.time),
encodeBlockId(header.lastBlockId),
encodeBytes(header.lastCommitHash),
encodeBytes(header.dataHash),
encodeBytes(header.validatorsHash),
encodeBytes(header.nextValidatorsHash),
encodeBytes(header.consensusHash),
encodeBytes(header.appHash),
encodeBytes(header.lastResultsHash),
encodeBytes(header.evidenceHash),
encodeBytes(header.proposerAddress),
];
return hashTree(encodedFields);
}

View File

@ -1,73 +0,0 @@
// Note: all exports in this module are public available via
// `import { tendermint33 } from "@cosmjs/tendermint-rpc"`
export {
AbciInfoRequest,
AbciQueryParams,
AbciQueryRequest,
BlockRequest,
BlockchainRequest,
BlockResultsRequest,
BroadcastTxRequest,
BroadcastTxParams,
CommitRequest,
GenesisRequest,
HealthRequest,
Method,
Request,
QueryTag,
StatusRequest,
SubscriptionEventType,
TxParams,
TxRequest,
TxSearchParams,
TxSearchRequest,
ValidatorsRequest,
ValidatorsParams,
} from "./requests";
export {
AbciInfoResponse,
AbciQueryResponse,
Attribute,
Block,
BlockchainResponse,
BlockGossipParams,
BlockId,
BlockMeta,
BlockParams,
BlockResponse,
BlockResultsResponse,
BroadcastTxAsyncResponse,
BroadcastTxCommitResponse,
broadcastTxCommitSuccess,
BroadcastTxSyncResponse,
broadcastTxSyncSuccess,
Commit,
CommitResponse,
ConsensusParams,
Event,
Evidence,
EvidenceParams,
GenesisResponse,
Header,
HealthResponse,
NewBlockEvent,
NewBlockHeaderEvent,
NodeInfo,
ProofOp,
QueryProof,
Response,
StatusResponse,
SyncInfo,
TxData,
TxEvent,
TxProof,
TxResponse,
TxSearchResponse,
TxSizeParams,
Validator,
ValidatorsResponse,
Version,
Vote,
VoteType,
} from "./responses";

View File

@ -1,41 +0,0 @@
import { buildQuery } from "./requests";
describe("Requests", () => {
describe("buildQuery", () => {
it("works for no input", () => {
const query = buildQuery({});
expect(query).toEqual("");
});
it("works for one tags", () => {
const query = buildQuery({ tags: [{ key: "abc", value: "def" }] });
expect(query).toEqual("abc='def'");
});
it("works for two tags", () => {
const query = buildQuery({
tags: [
{ key: "k", value: "9" },
{ key: "L", value: "7" },
],
});
expect(query).toEqual("k='9' AND L='7'");
});
it("works for raw input", () => {
const query = buildQuery({ raw: "aabbCCDD" });
expect(query).toEqual("aabbCCDD");
});
it("works for mixed input", () => {
const query = buildQuery({
tags: [
{ key: "k", value: "9" },
{ key: "L", value: "7" },
],
raw: "aabbCCDD",
});
expect(query).toEqual("k='9' AND L='7' AND aabbCCDD");
});
});
});

View File

@ -1,185 +0,0 @@
/* eslint-disable @typescript-eslint/naming-convention */
/**
* RPC methods as documented in https://docs.tendermint.com/master/rpc/
*
* Enum raw value must match the spelling in the "shell" example call (snake_case)
*/
export enum Method {
AbciInfo = "abci_info",
AbciQuery = "abci_query",
Block = "block",
/** Get block headers for minHeight <= height <= maxHeight. */
Blockchain = "blockchain",
BlockResults = "block_results",
BroadcastTxAsync = "broadcast_tx_async",
BroadcastTxSync = "broadcast_tx_sync",
BroadcastTxCommit = "broadcast_tx_commit",
Commit = "commit",
Genesis = "genesis",
Health = "health",
Status = "status",
Subscribe = "subscribe",
Tx = "tx",
TxSearch = "tx_search",
Validators = "validators",
Unsubscribe = "unsubscribe",
}
export type Request =
| AbciInfoRequest
| AbciQueryRequest
| BlockRequest
| BlockchainRequest
| BlockResultsRequest
| BroadcastTxRequest
| CommitRequest
| GenesisRequest
| HealthRequest
| StatusRequest
| TxRequest
| TxSearchRequest
| ValidatorsRequest;
/**
* Raw values must match the tendermint event name
*
* @see https://godoc.org/github.com/tendermint/tendermint/types#pkg-constants
*/
export enum SubscriptionEventType {
NewBlock = "NewBlock",
NewBlockHeader = "NewBlockHeader",
Tx = "Tx",
}
export interface AbciInfoRequest {
readonly method: Method.AbciInfo;
}
export interface AbciQueryRequest {
readonly method: Method.AbciQuery;
readonly params: AbciQueryParams;
}
export interface AbciQueryParams {
readonly path: string;
readonly data: Uint8Array;
readonly height?: number;
/**
* A flag that defines if proofs are included in the response or not.
*
* Internally this is mapped to the old inverse name `trusted` for Tendermint < 0.26.
* Starting with Tendermint 0.26, the default value changed from true to false.
*/
readonly prove?: boolean;
}
export interface BlockRequest {
readonly method: Method.Block;
readonly params: {
readonly height?: number;
};
}
export interface BlockchainRequest {
readonly method: Method.Blockchain;
readonly params: BlockchainRequestParams;
}
export interface BlockchainRequestParams {
readonly minHeight?: number;
readonly maxHeight?: number;
}
export interface BlockResultsRequest {
readonly method: Method.BlockResults;
readonly params: {
readonly height?: number;
};
}
export interface BroadcastTxRequest {
readonly method: Method.BroadcastTxAsync | Method.BroadcastTxSync | Method.BroadcastTxCommit;
readonly params: BroadcastTxParams;
}
export interface BroadcastTxParams {
readonly tx: Uint8Array;
}
export interface CommitRequest {
readonly method: Method.Commit;
readonly params: {
readonly height?: number;
};
}
export interface GenesisRequest {
readonly method: Method.Genesis;
}
export interface HealthRequest {
readonly method: Method.Health;
}
export interface StatusRequest {
readonly method: Method.Status;
}
export interface SubscribeRequest {
readonly method: Method.Subscribe;
readonly query: {
readonly type: SubscriptionEventType;
readonly raw?: string;
};
}
export interface QueryTag {
readonly key: string;
readonly value: string;
}
export interface TxRequest {
readonly method: Method.Tx;
readonly params: TxParams;
}
export interface TxParams {
readonly hash: Uint8Array;
readonly prove?: boolean;
}
// TODO: clarify this type
export interface TxSearchRequest {
readonly method: Method.TxSearch;
readonly params: TxSearchParams;
}
export interface TxSearchParams {
readonly query: string;
readonly prove?: boolean;
readonly page?: number;
readonly per_page?: number;
readonly order_by?: string;
}
export interface ValidatorsRequest {
readonly method: Method.Validators;
readonly params: ValidatorsParams;
}
export interface ValidatorsParams {
readonly height?: number;
readonly page?: number;
readonly per_page?: number;
}
export interface BuildQueryComponents {
readonly tags?: readonly QueryTag[];
readonly raw?: string;
}
export function buildQuery(components: BuildQueryComponents): string {
const tags = components.tags ? components.tags : [];
const tagComponents = tags.map((tag) => `${tag.key}='${tag.value}'`);
const rawComponents = components.raw ? [components.raw] : [];
return [...tagComponents, ...rawComponents].join(" AND ");
}

View File

@ -1,337 +0,0 @@
import { ReadonlyDate } from "readonly-date";
import { ReadonlyDateWithNanoseconds } from "../dates";
import { CommitSignature, ValidatorPubkey } from "../types";
export type Response =
| AbciInfoResponse
| AbciQueryResponse
| BlockResponse
| BlockResultsResponse
| BlockchainResponse
| BroadcastTxAsyncResponse
| BroadcastTxSyncResponse
| BroadcastTxCommitResponse
| CommitResponse
| GenesisResponse
| HealthResponse
| StatusResponse
| TxResponse
| TxSearchResponse
| ValidatorsResponse;
export interface AbciInfoResponse {
readonly data?: string;
readonly lastBlockHeight?: number;
readonly lastBlockAppHash?: Uint8Array;
}
export interface ProofOp {
readonly type: string;
readonly key: Uint8Array;
readonly data: Uint8Array;
}
export interface QueryProof {
readonly ops: readonly ProofOp[];
}
export interface AbciQueryResponse {
readonly key: Uint8Array;
readonly value: Uint8Array;
readonly proof?: QueryProof;
readonly height?: number;
readonly index?: number;
readonly code?: number; // non-falsy for errors
readonly log?: string;
}
export interface BlockResponse {
readonly blockId: BlockId;
readonly block: Block;
}
export interface BlockResultsResponse {
readonly height: number;
readonly results: readonly TxData[];
readonly validatorUpdates: readonly Validator[];
readonly consensusUpdates?: ConsensusParams;
readonly beginBlockEvents: readonly Event[];
readonly endBlockEvents: readonly Event[];
}
export interface BlockchainResponse {
readonly lastHeight: number;
readonly blockMetas: readonly BlockMeta[];
}
/** No data in here because RPC method BroadcastTxAsync "returns right away, with no response" */
export interface BroadcastTxAsyncResponse {}
export interface BroadcastTxSyncResponse extends TxData {
readonly hash: Uint8Array;
}
/**
* Returns true iff transaction made it successfully into the transaction pool
*/
export function broadcastTxSyncSuccess(res: BroadcastTxSyncResponse): boolean {
// code must be 0 on success
return res.code === 0;
}
export interface BroadcastTxCommitResponse {
readonly height: number;
readonly hash: Uint8Array;
readonly checkTx: TxData;
readonly deliverTx?: TxData;
}
/**
* Returns true iff transaction made it successfully into a block
* (i.e. success in `check_tx` and `deliver_tx` field)
*/
export function broadcastTxCommitSuccess(response: BroadcastTxCommitResponse): boolean {
// code must be 0 on success
// deliverTx may be present but empty on failure
return response.checkTx.code === 0 && !!response.deliverTx && response.deliverTx.code === 0;
}
export interface CommitResponse {
readonly header: Header;
readonly commit: Commit;
readonly canonical: boolean;
}
export interface GenesisResponse {
readonly genesisTime: ReadonlyDate;
readonly chainId: string;
readonly consensusParams: ConsensusParams;
readonly validators: readonly Validator[];
readonly appHash: Uint8Array;
readonly appState: Record<string, unknown> | undefined;
}
export type HealthResponse = null;
export interface StatusResponse {
readonly nodeInfo: NodeInfo;
readonly syncInfo: SyncInfo;
readonly validatorInfo: Validator;
}
/**
* A transaction from RPC calls like search.
*
* Try to keep this compatible to TxEvent
*/
export interface TxResponse {
readonly tx: Uint8Array;
readonly hash: Uint8Array;
readonly height: number;
readonly index: number;
readonly result: TxData;
readonly proof?: TxProof;
}
export interface TxSearchResponse {
readonly txs: readonly TxResponse[];
readonly totalCount: number;
}
export interface ValidatorsResponse {
readonly blockHeight: number;
readonly validators: readonly Validator[];
readonly count: number;
readonly total: number;
}
// Events
export interface NewBlockEvent extends Block {}
export interface NewBlockHeaderEvent extends Header {}
export interface TxEvent {
readonly tx: Uint8Array;
readonly hash: Uint8Array;
readonly height: number;
/** @deprecated this value is not set in Tendermint 0.34+ */
readonly index?: number;
readonly result: TxData;
}
// Helper items used above
/** An event attribute */
export interface Attribute {
readonly key: Uint8Array;
readonly value: Uint8Array;
}
export interface Event {
readonly type: string;
readonly attributes: readonly Attribute[];
}
export interface TxData {
readonly code: number;
readonly log?: string;
readonly data?: Uint8Array;
readonly events: readonly Event[];
// readonly fees?: any;
}
export interface TxProof {
readonly data: Uint8Array;
readonly rootHash: Uint8Array;
readonly proof: {
readonly total: number;
readonly index: number;
readonly leafHash: Uint8Array;
readonly aunts: readonly Uint8Array[];
};
}
export interface BlockMeta {
readonly blockId: BlockId;
readonly header: Header;
// TODO: Add blockSize (e.g "block_size": "471")
// TODO: Add numTxs (e.g "num_txs": "0")
}
export interface BlockId {
readonly hash: Uint8Array;
readonly parts: {
readonly total: number;
readonly hash: Uint8Array;
};
}
export interface Block {
readonly header: Header;
readonly lastCommit: Commit;
readonly txs: readonly Uint8Array[];
readonly evidence?: readonly Evidence[];
}
export interface Evidence {
readonly type: string;
readonly validator: Validator;
readonly height: number;
readonly time: number;
readonly totalVotingPower: number;
}
export interface Commit {
readonly blockId: BlockId;
readonly height: number;
readonly round: number;
readonly signatures: readonly CommitSignature[];
}
/**
* raw values from https://github.com/tendermint/tendermint/blob/dfa9a9a30a666132425b29454e90a472aa579a48/types/vote.go#L44
*/
export enum VoteType {
PreVote = 1,
PreCommit = 2,
}
export interface Vote {
readonly type: VoteType;
readonly validatorAddress: Uint8Array;
readonly validatorIndex: number;
readonly height: number;
readonly round: number;
readonly timestamp: ReadonlyDate;
readonly blockId: BlockId;
readonly signature: Uint8Array;
}
export interface Version {
readonly block: number;
readonly app: number;
}
// https://github.com/tendermint/tendermint/blob/v0.31.8/docs/spec/blockchain/blockchain.md
export interface Header {
// basic block info
readonly version: Version;
readonly chainId: string;
readonly height: number;
readonly time: ReadonlyDateWithNanoseconds;
// prev block info
readonly lastBlockId: BlockId;
// hashes of block data
readonly lastCommitHash: Uint8Array;
readonly dataHash: Uint8Array; // empty when number of transaction is 0
// hashes from the app output from the prev block
readonly validatorsHash: Uint8Array;
readonly nextValidatorsHash: Uint8Array;
readonly consensusHash: Uint8Array;
readonly appHash: Uint8Array;
readonly lastResultsHash: Uint8Array;
// consensus info
readonly evidenceHash: Uint8Array;
readonly proposerAddress: Uint8Array;
}
export interface NodeInfo {
readonly id: Uint8Array;
/** IP and port */
readonly listenAddr: string;
readonly network: string;
readonly version: string;
readonly channels: string; // ???
readonly moniker: string;
readonly other: Map<string, string>;
readonly protocolVersion: {
readonly p2p: number;
readonly block: number;
readonly app: number;
};
}
export interface SyncInfo {
readonly latestBlockHash: Uint8Array;
readonly latestAppHash: Uint8Array;
readonly latestBlockHeight: number;
readonly latestBlockTime: ReadonlyDate;
readonly catchingUp: boolean;
}
export interface Validator {
readonly address: Uint8Array;
readonly pubkey?: ValidatorPubkey;
readonly votingPower: number;
readonly proposerPriority?: number;
}
export interface ConsensusParams {
readonly block: BlockParams;
readonly evidence: EvidenceParams;
}
export interface BlockParams {
readonly maxBytes: number;
readonly maxGas: number;
}
export interface TxSizeParams {
readonly maxBytes: number;
readonly maxGas: number;
}
export interface BlockGossipParams {
readonly blockPartSizeBytes: number;
}
export interface EvidenceParams {
readonly maxAgeNumBlocks: number;
readonly maxAgeDuration: number;
}