UNPKG

interchainjs

Version:

InterchainJS is a JavaScript library for interacting with Cosmos SDK based blockchains.

1,200 lines 77.8 kB
import { Proof } from "../crypto/proof"; import { Consensus } from "../version/types"; import { Timestamp } from "../../google/protobuf/timestamp"; import { ValidatorSet } from "./validator"; import { BinaryReader, BinaryWriter } from "../../binary"; import { bytesFromBase64, base64FromBytes, toTimestamp, fromTimestamp, isSet } from "../../helpers"; import { GlobalDecoderRegistry } from "../../registry"; /** SignedMsgType is a type of signed message in the consensus. */ export var SignedMsgType; (function (SignedMsgType) { SignedMsgType[SignedMsgType["SIGNED_MSG_TYPE_UNKNOWN"] = 0] = "SIGNED_MSG_TYPE_UNKNOWN"; /** SIGNED_MSG_TYPE_PREVOTE - Votes */ SignedMsgType[SignedMsgType["SIGNED_MSG_TYPE_PREVOTE"] = 1] = "SIGNED_MSG_TYPE_PREVOTE"; SignedMsgType[SignedMsgType["SIGNED_MSG_TYPE_PRECOMMIT"] = 2] = "SIGNED_MSG_TYPE_PRECOMMIT"; /** SIGNED_MSG_TYPE_PROPOSAL - Proposals */ SignedMsgType[SignedMsgType["SIGNED_MSG_TYPE_PROPOSAL"] = 32] = "SIGNED_MSG_TYPE_PROPOSAL"; SignedMsgType[SignedMsgType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED"; })(SignedMsgType || (SignedMsgType = {})); export const SignedMsgTypeAmino = SignedMsgType; export function signedMsgTypeFromJSON(object) { switch (object) { case 0: case "SIGNED_MSG_TYPE_UNKNOWN": return SignedMsgType.SIGNED_MSG_TYPE_UNKNOWN; case 1: case "SIGNED_MSG_TYPE_PREVOTE": return SignedMsgType.SIGNED_MSG_TYPE_PREVOTE; case 2: case "SIGNED_MSG_TYPE_PRECOMMIT": return SignedMsgType.SIGNED_MSG_TYPE_PRECOMMIT; case 32: case "SIGNED_MSG_TYPE_PROPOSAL": return SignedMsgType.SIGNED_MSG_TYPE_PROPOSAL; case -1: case "UNRECOGNIZED": default: return SignedMsgType.UNRECOGNIZED; } } export function signedMsgTypeToJSON(object) { switch (object) { case SignedMsgType.SIGNED_MSG_TYPE_UNKNOWN: return "SIGNED_MSG_TYPE_UNKNOWN"; case SignedMsgType.SIGNED_MSG_TYPE_PREVOTE: return "SIGNED_MSG_TYPE_PREVOTE"; case SignedMsgType.SIGNED_MSG_TYPE_PRECOMMIT: return "SIGNED_MSG_TYPE_PRECOMMIT"; case SignedMsgType.SIGNED_MSG_TYPE_PROPOSAL: return "SIGNED_MSG_TYPE_PROPOSAL"; case SignedMsgType.UNRECOGNIZED: default: return "UNRECOGNIZED"; } } function createBasePartSetHeader() { return { total: 0, hash: new Uint8Array() }; } /** * PartsetHeader * @name PartSetHeader * @package tendermint.types * @see proto type: tendermint.types.PartSetHeader */ export const PartSetHeader = { typeUrl: "/tendermint.types.PartSetHeader", is(o) { return o && (o.$typeUrl === PartSetHeader.typeUrl || typeof o.total === "number" && (o.hash instanceof Uint8Array || typeof o.hash === "string")); }, isAmino(o) { return o && (o.$typeUrl === PartSetHeader.typeUrl || typeof o.total === "number" && (o.hash instanceof Uint8Array || typeof o.hash === "string")); }, encode(message, writer = BinaryWriter.create()) { if (message.total !== 0) { writer.uint32(8).uint32(message.total); } if (message.hash.length !== 0) { writer.uint32(18).bytes(message.hash); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBasePartSetHeader(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.total = reader.uint32(); break; case 2: message.hash = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBasePartSetHeader(); message.total = object.total ?? 0; message.hash = object.hash ?? new Uint8Array(); return message; }, fromAmino(object) { const message = createBasePartSetHeader(); if (object.total !== undefined && object.total !== null) { message.total = object.total; } if (object.hash !== undefined && object.hash !== null) { message.hash = bytesFromBase64(object.hash); } return message; }, toAmino(message) { const obj = {}; obj.total = message.total === 0 ? undefined : message.total; obj.hash = message.hash ? base64FromBytes(message.hash) : undefined; return obj; }, fromAminoMsg(object) { return PartSetHeader.fromAmino(object.value); }, fromProtoMsg(message) { return PartSetHeader.decode(message.value); }, toProto(message) { return PartSetHeader.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.PartSetHeader", value: PartSetHeader.encode(message).finish() }; }, registerTypeUrl() { } }; function createBasePart() { return { index: 0, bytes: new Uint8Array(), proof: Proof.fromPartial({}) }; } /** * @name Part * @package tendermint.types * @see proto type: tendermint.types.Part */ export const Part = { typeUrl: "/tendermint.types.Part", is(o) { return o && (o.$typeUrl === Part.typeUrl || typeof o.index === "number" && (o.bytes instanceof Uint8Array || typeof o.bytes === "string") && Proof.is(o.proof)); }, isAmino(o) { return o && (o.$typeUrl === Part.typeUrl || typeof o.index === "number" && (o.bytes instanceof Uint8Array || typeof o.bytes === "string") && Proof.isAmino(o.proof)); }, encode(message, writer = BinaryWriter.create()) { if (message.index !== 0) { writer.uint32(8).uint32(message.index); } if (message.bytes.length !== 0) { writer.uint32(18).bytes(message.bytes); } if (message.proof !== undefined) { Proof.encode(message.proof, writer.uint32(26).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBasePart(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.index = reader.uint32(); break; case 2: message.bytes = reader.bytes(); break; case 3: message.proof = Proof.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBasePart(); message.index = object.index ?? 0; message.bytes = object.bytes ?? new Uint8Array(); message.proof = object.proof !== undefined && object.proof !== null ? Proof.fromPartial(object.proof) : undefined; return message; }, fromAmino(object) { const message = createBasePart(); if (object.index !== undefined && object.index !== null) { message.index = object.index; } if (object.bytes !== undefined && object.bytes !== null) { message.bytes = bytesFromBase64(object.bytes); } if (object.proof !== undefined && object.proof !== null) { message.proof = Proof.fromAmino(object.proof); } return message; }, toAmino(message) { const obj = {}; obj.index = message.index === 0 ? undefined : message.index; obj.bytes = message.bytes ? base64FromBytes(message.bytes) : undefined; obj.proof = message.proof ? Proof.toAmino(message.proof) : undefined; return obj; }, fromAminoMsg(object) { return Part.fromAmino(object.value); }, fromProtoMsg(message) { return Part.decode(message.value); }, toProto(message) { return Part.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.Part", value: Part.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Part.typeUrl)) { return; } Proof.registerTypeUrl(); } }; function createBaseBlockID() { return { hash: new Uint8Array(), partSetHeader: PartSetHeader.fromPartial({}) }; } /** * BlockID * @name BlockID * @package tendermint.types * @see proto type: tendermint.types.BlockID */ export const BlockID = { typeUrl: "/tendermint.types.BlockID", is(o) { return o && (o.$typeUrl === BlockID.typeUrl || (o.hash instanceof Uint8Array || typeof o.hash === "string") && PartSetHeader.is(o.partSetHeader)); }, isAmino(o) { return o && (o.$typeUrl === BlockID.typeUrl || (o.hash instanceof Uint8Array || typeof o.hash === "string") && PartSetHeader.isAmino(o.part_set_header)); }, encode(message, writer = BinaryWriter.create()) { if (message.hash.length !== 0) { writer.uint32(10).bytes(message.hash); } if (message.partSetHeader !== undefined) { PartSetHeader.encode(message.partSetHeader, writer.uint32(18).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseBlockID(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.hash = reader.bytes(); break; case 2: message.partSetHeader = PartSetHeader.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseBlockID(); message.hash = object.hash ?? new Uint8Array(); message.partSetHeader = object.partSetHeader !== undefined && object.partSetHeader !== null ? PartSetHeader.fromPartial(object.partSetHeader) : undefined; return message; }, fromAmino(object) { const message = createBaseBlockID(); if (object.hash !== undefined && object.hash !== null) { message.hash = bytesFromBase64(object.hash); } if (object.part_set_header !== undefined && object.part_set_header !== null) { message.partSetHeader = PartSetHeader.fromAmino(object.part_set_header); } return message; }, toAmino(message) { const obj = {}; obj.hash = message.hash ? base64FromBytes(message.hash) : undefined; obj.part_set_header = message.partSetHeader ? PartSetHeader.toAmino(message.partSetHeader) : undefined; return obj; }, fromAminoMsg(object) { return BlockID.fromAmino(object.value); }, fromProtoMsg(message) { return BlockID.decode(message.value); }, toProto(message) { return BlockID.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.BlockID", value: BlockID.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(BlockID.typeUrl)) { return; } PartSetHeader.registerTypeUrl(); } }; function createBaseHeader() { return { version: Consensus.fromPartial({}), chainId: "", height: BigInt(0), time: new Date(), lastBlockId: BlockID.fromPartial({}), lastCommitHash: new Uint8Array(), dataHash: new Uint8Array(), validatorsHash: new Uint8Array(), nextValidatorsHash: new Uint8Array(), consensusHash: new Uint8Array(), appHash: new Uint8Array(), lastResultsHash: new Uint8Array(), evidenceHash: new Uint8Array(), proposerAddress: new Uint8Array() }; } /** * Header defines the structure of a block header. * @name Header * @package tendermint.types * @see proto type: tendermint.types.Header */ export const Header = { typeUrl: "/tendermint.types.Header", is(o) { return o && (o.$typeUrl === Header.typeUrl || Consensus.is(o.version) && typeof o.chainId === "string" && typeof o.height === "bigint" && Timestamp.is(o.time) && BlockID.is(o.lastBlockId) && (o.lastCommitHash instanceof Uint8Array || typeof o.lastCommitHash === "string") && (o.dataHash instanceof Uint8Array || typeof o.dataHash === "string") && (o.validatorsHash instanceof Uint8Array || typeof o.validatorsHash === "string") && (o.nextValidatorsHash instanceof Uint8Array || typeof o.nextValidatorsHash === "string") && (o.consensusHash instanceof Uint8Array || typeof o.consensusHash === "string") && (o.appHash instanceof Uint8Array || typeof o.appHash === "string") && (o.lastResultsHash instanceof Uint8Array || typeof o.lastResultsHash === "string") && (o.evidenceHash instanceof Uint8Array || typeof o.evidenceHash === "string") && (o.proposerAddress instanceof Uint8Array || typeof o.proposerAddress === "string")); }, isAmino(o) { return o && (o.$typeUrl === Header.typeUrl || Consensus.isAmino(o.version) && typeof o.chain_id === "string" && typeof o.height === "bigint" && Timestamp.isAmino(o.time) && BlockID.isAmino(o.last_block_id) && (o.last_commit_hash instanceof Uint8Array || typeof o.last_commit_hash === "string") && (o.data_hash instanceof Uint8Array || typeof o.data_hash === "string") && (o.validators_hash instanceof Uint8Array || typeof o.validators_hash === "string") && (o.next_validators_hash instanceof Uint8Array || typeof o.next_validators_hash === "string") && (o.consensus_hash instanceof Uint8Array || typeof o.consensus_hash === "string") && (o.app_hash instanceof Uint8Array || typeof o.app_hash === "string") && (o.last_results_hash instanceof Uint8Array || typeof o.last_results_hash === "string") && (o.evidence_hash instanceof Uint8Array || typeof o.evidence_hash === "string") && (o.proposer_address instanceof Uint8Array || typeof o.proposer_address === "string")); }, encode(message, writer = BinaryWriter.create()) { if (message.version !== undefined) { Consensus.encode(message.version, writer.uint32(10).fork()).ldelim(); } if (message.chainId !== "") { writer.uint32(18).string(message.chainId); } if (message.height !== BigInt(0)) { writer.uint32(24).int64(message.height); } if (message.time !== undefined) { Timestamp.encode(toTimestamp(message.time), writer.uint32(34).fork()).ldelim(); } if (message.lastBlockId !== undefined) { BlockID.encode(message.lastBlockId, writer.uint32(42).fork()).ldelim(); } if (message.lastCommitHash.length !== 0) { writer.uint32(50).bytes(message.lastCommitHash); } if (message.dataHash.length !== 0) { writer.uint32(58).bytes(message.dataHash); } if (message.validatorsHash.length !== 0) { writer.uint32(66).bytes(message.validatorsHash); } if (message.nextValidatorsHash.length !== 0) { writer.uint32(74).bytes(message.nextValidatorsHash); } if (message.consensusHash.length !== 0) { writer.uint32(82).bytes(message.consensusHash); } if (message.appHash.length !== 0) { writer.uint32(90).bytes(message.appHash); } if (message.lastResultsHash.length !== 0) { writer.uint32(98).bytes(message.lastResultsHash); } if (message.evidenceHash.length !== 0) { writer.uint32(106).bytes(message.evidenceHash); } if (message.proposerAddress.length !== 0) { writer.uint32(114).bytes(message.proposerAddress); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseHeader(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.version = Consensus.decode(reader, reader.uint32()); break; case 2: message.chainId = reader.string(); break; case 3: message.height = reader.int64(); break; case 4: message.time = fromTimestamp(Timestamp.decode(reader, reader.uint32())); break; case 5: message.lastBlockId = BlockID.decode(reader, reader.uint32()); break; case 6: message.lastCommitHash = reader.bytes(); break; case 7: message.dataHash = reader.bytes(); break; case 8: message.validatorsHash = reader.bytes(); break; case 9: message.nextValidatorsHash = reader.bytes(); break; case 10: message.consensusHash = reader.bytes(); break; case 11: message.appHash = reader.bytes(); break; case 12: message.lastResultsHash = reader.bytes(); break; case 13: message.evidenceHash = reader.bytes(); break; case 14: message.proposerAddress = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseHeader(); message.version = object.version !== undefined && object.version !== null ? Consensus.fromPartial(object.version) : undefined; message.chainId = object.chainId ?? ""; message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0); message.time = object.time ?? undefined; message.lastBlockId = object.lastBlockId !== undefined && object.lastBlockId !== null ? BlockID.fromPartial(object.lastBlockId) : undefined; message.lastCommitHash = object.lastCommitHash ?? new Uint8Array(); message.dataHash = object.dataHash ?? new Uint8Array(); message.validatorsHash = object.validatorsHash ?? new Uint8Array(); message.nextValidatorsHash = object.nextValidatorsHash ?? new Uint8Array(); message.consensusHash = object.consensusHash ?? new Uint8Array(); message.appHash = object.appHash ?? new Uint8Array(); message.lastResultsHash = object.lastResultsHash ?? new Uint8Array(); message.evidenceHash = object.evidenceHash ?? new Uint8Array(); message.proposerAddress = object.proposerAddress ?? new Uint8Array(); return message; }, fromAmino(object) { const message = createBaseHeader(); if (object.version !== undefined && object.version !== null) { message.version = Consensus.fromAmino(object.version); } if (object.chain_id !== undefined && object.chain_id !== null) { message.chainId = object.chain_id; } if (object.height !== undefined && object.height !== null) { message.height = BigInt(object.height); } if (object.time !== undefined && object.time !== null) { message.time = fromTimestamp(Timestamp.fromAmino(object.time)); } if (object.last_block_id !== undefined && object.last_block_id !== null) { message.lastBlockId = BlockID.fromAmino(object.last_block_id); } if (object.last_commit_hash !== undefined && object.last_commit_hash !== null) { message.lastCommitHash = bytesFromBase64(object.last_commit_hash); } if (object.data_hash !== undefined && object.data_hash !== null) { message.dataHash = bytesFromBase64(object.data_hash); } if (object.validators_hash !== undefined && object.validators_hash !== null) { message.validatorsHash = bytesFromBase64(object.validators_hash); } if (object.next_validators_hash !== undefined && object.next_validators_hash !== null) { message.nextValidatorsHash = bytesFromBase64(object.next_validators_hash); } if (object.consensus_hash !== undefined && object.consensus_hash !== null) { message.consensusHash = bytesFromBase64(object.consensus_hash); } if (object.app_hash !== undefined && object.app_hash !== null) { message.appHash = bytesFromBase64(object.app_hash); } if (object.last_results_hash !== undefined && object.last_results_hash !== null) { message.lastResultsHash = bytesFromBase64(object.last_results_hash); } if (object.evidence_hash !== undefined && object.evidence_hash !== null) { message.evidenceHash = bytesFromBase64(object.evidence_hash); } if (object.proposer_address !== undefined && object.proposer_address !== null) { message.proposerAddress = bytesFromBase64(object.proposer_address); } return message; }, toAmino(message) { const obj = {}; obj.version = message.version ? Consensus.toAmino(message.version) : undefined; obj.chain_id = message.chainId === "" ? undefined : message.chainId; obj.height = message.height !== BigInt(0) ? message.height?.toString() : undefined; obj.time = message.time ? Timestamp.toAmino(toTimestamp(message.time)) : undefined; obj.last_block_id = message.lastBlockId ? BlockID.toAmino(message.lastBlockId) : undefined; obj.last_commit_hash = message.lastCommitHash ? base64FromBytes(message.lastCommitHash) : undefined; obj.data_hash = message.dataHash ? base64FromBytes(message.dataHash) : undefined; obj.validators_hash = message.validatorsHash ? base64FromBytes(message.validatorsHash) : undefined; obj.next_validators_hash = message.nextValidatorsHash ? base64FromBytes(message.nextValidatorsHash) : undefined; obj.consensus_hash = message.consensusHash ? base64FromBytes(message.consensusHash) : undefined; obj.app_hash = message.appHash ? base64FromBytes(message.appHash) : undefined; obj.last_results_hash = message.lastResultsHash ? base64FromBytes(message.lastResultsHash) : undefined; obj.evidence_hash = message.evidenceHash ? base64FromBytes(message.evidenceHash) : undefined; obj.proposer_address = message.proposerAddress ? base64FromBytes(message.proposerAddress) : undefined; return obj; }, fromAminoMsg(object) { return Header.fromAmino(object.value); }, fromProtoMsg(message) { return Header.decode(message.value); }, toProto(message) { return Header.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.Header", value: Header.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Header.typeUrl)) { return; } Consensus.registerTypeUrl(); BlockID.registerTypeUrl(); } }; function createBaseData() { return { txs: [] }; } /** * Data contains the set of transactions included in the block * @name Data * @package tendermint.types * @see proto type: tendermint.types.Data */ export const Data = { typeUrl: "/tendermint.types.Data", is(o) { return o && (o.$typeUrl === Data.typeUrl || Array.isArray(o.txs) && (!o.txs.length || o.txs[0] instanceof Uint8Array || typeof o.txs[0] === "string")); }, isAmino(o) { return o && (o.$typeUrl === Data.typeUrl || Array.isArray(o.txs) && (!o.txs.length || o.txs[0] instanceof Uint8Array || typeof o.txs[0] === "string")); }, encode(message, writer = BinaryWriter.create()) { for (const v of message.txs) { writer.uint32(10).bytes(v); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseData(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.txs.push(reader.bytes()); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseData(); message.txs = object.txs?.map(e => e) || []; return message; }, fromAmino(object) { const message = createBaseData(); message.txs = object.txs?.map(e => bytesFromBase64(e)) || []; return message; }, toAmino(message) { const obj = {}; if (message.txs) { obj.txs = message.txs.map(e => base64FromBytes(e)); } else { obj.txs = message.txs; } return obj; }, fromAminoMsg(object) { return Data.fromAmino(object.value); }, fromProtoMsg(message) { return Data.decode(message.value); }, toProto(message) { return Data.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.Data", value: Data.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseVote() { return { type: 0, height: BigInt(0), round: 0, blockId: BlockID.fromPartial({}), timestamp: new Date(), validatorAddress: new Uint8Array(), validatorIndex: 0, signature: new Uint8Array(), extension: new Uint8Array(), extensionSignature: new Uint8Array() }; } /** * Vote represents a prevote or precommit vote from validators for * consensus. * @name Vote * @package tendermint.types * @see proto type: tendermint.types.Vote */ export const Vote = { typeUrl: "/tendermint.types.Vote", is(o) { return o && (o.$typeUrl === Vote.typeUrl || isSet(o.type) && typeof o.height === "bigint" && typeof o.round === "number" && BlockID.is(o.blockId) && Timestamp.is(o.timestamp) && (o.validatorAddress instanceof Uint8Array || typeof o.validatorAddress === "string") && typeof o.validatorIndex === "number" && (o.signature instanceof Uint8Array || typeof o.signature === "string") && (o.extension instanceof Uint8Array || typeof o.extension === "string") && (o.extensionSignature instanceof Uint8Array || typeof o.extensionSignature === "string")); }, isAmino(o) { return o && (o.$typeUrl === Vote.typeUrl || isSet(o.type) && typeof o.height === "bigint" && typeof o.round === "number" && BlockID.isAmino(o.block_id) && Timestamp.isAmino(o.timestamp) && (o.validator_address instanceof Uint8Array || typeof o.validator_address === "string") && typeof o.validator_index === "number" && (o.signature instanceof Uint8Array || typeof o.signature === "string") && (o.extension instanceof Uint8Array || typeof o.extension === "string") && (o.extension_signature instanceof Uint8Array || typeof o.extension_signature === "string")); }, encode(message, writer = BinaryWriter.create()) { if (message.type !== 0) { writer.uint32(8).int32(message.type); } if (message.height !== BigInt(0)) { writer.uint32(16).int64(message.height); } if (message.round !== 0) { writer.uint32(24).int32(message.round); } if (message.blockId !== undefined) { BlockID.encode(message.blockId, writer.uint32(34).fork()).ldelim(); } if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(42).fork()).ldelim(); } if (message.validatorAddress.length !== 0) { writer.uint32(50).bytes(message.validatorAddress); } if (message.validatorIndex !== 0) { writer.uint32(56).int32(message.validatorIndex); } if (message.signature.length !== 0) { writer.uint32(66).bytes(message.signature); } if (message.extension.length !== 0) { writer.uint32(74).bytes(message.extension); } if (message.extensionSignature.length !== 0) { writer.uint32(82).bytes(message.extensionSignature); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseVote(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.type = reader.int32(); break; case 2: message.height = reader.int64(); break; case 3: message.round = reader.int32(); break; case 4: message.blockId = BlockID.decode(reader, reader.uint32()); break; case 5: message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); break; case 6: message.validatorAddress = reader.bytes(); break; case 7: message.validatorIndex = reader.int32(); break; case 8: message.signature = reader.bytes(); break; case 9: message.extension = reader.bytes(); break; case 10: message.extensionSignature = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseVote(); message.type = object.type ?? 0; message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0); message.round = object.round ?? 0; message.blockId = object.blockId !== undefined && object.blockId !== null ? BlockID.fromPartial(object.blockId) : undefined; message.timestamp = object.timestamp ?? undefined; message.validatorAddress = object.validatorAddress ?? new Uint8Array(); message.validatorIndex = object.validatorIndex ?? 0; message.signature = object.signature ?? new Uint8Array(); message.extension = object.extension ?? new Uint8Array(); message.extensionSignature = object.extensionSignature ?? new Uint8Array(); return message; }, fromAmino(object) { const message = createBaseVote(); if (object.type !== undefined && object.type !== null) { message.type = object.type; } if (object.height !== undefined && object.height !== null) { message.height = BigInt(object.height); } if (object.round !== undefined && object.round !== null) { message.round = object.round; } if (object.block_id !== undefined && object.block_id !== null) { message.blockId = BlockID.fromAmino(object.block_id); } if (object.timestamp !== undefined && object.timestamp !== null) { message.timestamp = fromTimestamp(Timestamp.fromAmino(object.timestamp)); } if (object.validator_address !== undefined && object.validator_address !== null) { message.validatorAddress = bytesFromBase64(object.validator_address); } if (object.validator_index !== undefined && object.validator_index !== null) { message.validatorIndex = object.validator_index; } if (object.signature !== undefined && object.signature !== null) { message.signature = bytesFromBase64(object.signature); } if (object.extension !== undefined && object.extension !== null) { message.extension = bytesFromBase64(object.extension); } if (object.extension_signature !== undefined && object.extension_signature !== null) { message.extensionSignature = bytesFromBase64(object.extension_signature); } return message; }, toAmino(message) { const obj = {}; obj.type = message.type === 0 ? undefined : message.type; obj.height = message.height !== BigInt(0) ? message.height?.toString() : undefined; obj.round = message.round === 0 ? undefined : message.round; obj.block_id = message.blockId ? BlockID.toAmino(message.blockId) : undefined; obj.timestamp = message.timestamp ? Timestamp.toAmino(toTimestamp(message.timestamp)) : undefined; obj.validator_address = message.validatorAddress ? base64FromBytes(message.validatorAddress) : undefined; obj.validator_index = message.validatorIndex === 0 ? undefined : message.validatorIndex; obj.signature = message.signature ? base64FromBytes(message.signature) : undefined; obj.extension = message.extension ? base64FromBytes(message.extension) : undefined; obj.extension_signature = message.extensionSignature ? base64FromBytes(message.extensionSignature) : undefined; return obj; }, fromAminoMsg(object) { return Vote.fromAmino(object.value); }, fromProtoMsg(message) { return Vote.decode(message.value); }, toProto(message) { return Vote.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.Vote", value: Vote.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Vote.typeUrl)) { return; } BlockID.registerTypeUrl(); } }; function createBaseCommit() { return { height: BigInt(0), round: 0, blockId: BlockID.fromPartial({}), signatures: [] }; } /** * Commit contains the evidence that a block was committed by a set of validators. * @name Commit * @package tendermint.types * @see proto type: tendermint.types.Commit */ export const Commit = { typeUrl: "/tendermint.types.Commit", is(o) { return o && (o.$typeUrl === Commit.typeUrl || typeof o.height === "bigint" && typeof o.round === "number" && BlockID.is(o.blockId) && Array.isArray(o.signatures) && (!o.signatures.length || CommitSig.is(o.signatures[0]))); }, isAmino(o) { return o && (o.$typeUrl === Commit.typeUrl || typeof o.height === "bigint" && typeof o.round === "number" && BlockID.isAmino(o.block_id) && Array.isArray(o.signatures) && (!o.signatures.length || CommitSig.isAmino(o.signatures[0]))); }, encode(message, writer = BinaryWriter.create()) { if (message.height !== BigInt(0)) { writer.uint32(8).int64(message.height); } if (message.round !== 0) { writer.uint32(16).int32(message.round); } if (message.blockId !== undefined) { BlockID.encode(message.blockId, writer.uint32(26).fork()).ldelim(); } for (const v of message.signatures) { CommitSig.encode(v, writer.uint32(34).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseCommit(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.height = reader.int64(); break; case 2: message.round = reader.int32(); break; case 3: message.blockId = BlockID.decode(reader, reader.uint32()); break; case 4: message.signatures.push(CommitSig.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseCommit(); message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0); message.round = object.round ?? 0; message.blockId = object.blockId !== undefined && object.blockId !== null ? BlockID.fromPartial(object.blockId) : undefined; message.signatures = object.signatures?.map(e => CommitSig.fromPartial(e)) || []; return message; }, fromAmino(object) { const message = createBaseCommit(); if (object.height !== undefined && object.height !== null) { message.height = BigInt(object.height); } if (object.round !== undefined && object.round !== null) { message.round = object.round; } if (object.block_id !== undefined && object.block_id !== null) { message.blockId = BlockID.fromAmino(object.block_id); } message.signatures = object.signatures?.map(e => CommitSig.fromAmino(e)) || []; return message; }, toAmino(message) { const obj = {}; obj.height = message.height !== BigInt(0) ? message.height?.toString() : undefined; obj.round = message.round === 0 ? undefined : message.round; obj.block_id = message.blockId ? BlockID.toAmino(message.blockId) : undefined; if (message.signatures) { obj.signatures = message.signatures.map(e => e ? CommitSig.toAmino(e) : undefined); } else { obj.signatures = message.signatures; } return obj; }, fromAminoMsg(object) { return Commit.fromAmino(object.value); }, fromProtoMsg(message) { return Commit.decode(message.value); }, toProto(message) { return Commit.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.Commit", value: Commit.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Commit.typeUrl)) { return; } BlockID.registerTypeUrl(); CommitSig.registerTypeUrl(); } }; function createBaseCommitSig() { return { blockIdFlag: 0, validatorAddress: new Uint8Array(), timestamp: new Date(), signature: new Uint8Array() }; } /** * CommitSig is a part of the Vote included in a Commit. * @name CommitSig * @package tendermint.types * @see proto type: tendermint.types.CommitSig */ export const CommitSig = { typeUrl: "/tendermint.types.CommitSig", is(o) { return o && (o.$typeUrl === CommitSig.typeUrl || isSet(o.blockIdFlag) && (o.validatorAddress instanceof Uint8Array || typeof o.validatorAddress === "string") && Timestamp.is(o.timestamp) && (o.signature instanceof Uint8Array || typeof o.signature === "string")); }, isAmino(o) { return o && (o.$typeUrl === CommitSig.typeUrl || isSet(o.block_id_flag) && (o.validator_address instanceof Uint8Array || typeof o.validator_address === "string") && Timestamp.isAmino(o.timestamp) && (o.signature instanceof Uint8Array || typeof o.signature === "string")); }, encode(message, writer = BinaryWriter.create()) { if (message.blockIdFlag !== 0) { writer.uint32(8).int32(message.blockIdFlag); } if (message.validatorAddress.length !== 0) { writer.uint32(18).bytes(message.validatorAddress); } if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(26).fork()).ldelim(); } if (message.signature.length !== 0) { writer.uint32(34).bytes(message.signature); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseCommitSig(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.blockIdFlag = reader.int32(); break; case 2: message.validatorAddress = reader.bytes(); break; case 3: message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); break; case 4: message.signature = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseCommitSig(); message.blockIdFlag = object.blockIdFlag ?? 0; message.validatorAddress = object.validatorAddress ?? new Uint8Array(); message.timestamp = object.timestamp ?? undefined; message.signature = object.signature ?? new Uint8Array(); return message; }, fromAmino(object) { const message = createBaseCommitSig(); if (object.block_id_flag !== undefined && object.block_id_flag !== null) { message.blockIdFlag = object.block_id_flag; } if (object.validator_address !== undefined && object.validator_address !== null) { message.validatorAddress = bytesFromBase64(object.validator_address); } if (object.timestamp !== undefined && object.timestamp !== null) { message.timestamp = fromTimestamp(Timestamp.fromAmino(object.timestamp)); } if (object.signature !== undefined && object.signature !== null) { message.signature = bytesFromBase64(object.signature); } return message; }, toAmino(message) { const obj = {}; obj.block_id_flag = message.blockIdFlag === 0 ? undefined : message.blockIdFlag; obj.validator_address = message.validatorAddress ? base64FromBytes(message.validatorAddress) : undefined; obj.timestamp = message.timestamp ? Timestamp.toAmino(toTimestamp(message.timestamp)) : undefined; obj.signature = message.signature ? base64FromBytes(message.signature) : undefined; return obj; }, fromAminoMsg(object) { return CommitSig.fromAmino(object.value); }, fromProtoMsg(message) { return CommitSig.decode(message.value); }, toProto(message) { return CommitSig.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.CommitSig", value: CommitSig.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseExtendedCommit() { return { height: BigInt(0), round: 0, blockId: BlockID.fromPartial({}), extendedSignatures: [] }; } /** * @name ExtendedCommit * @package tendermint.types * @see proto type: tendermint.types.ExtendedCommit */ export const ExtendedCommit = { typeUrl: "/tendermint.types.ExtendedCommit", is(o) { return o && (o.$typeUrl === ExtendedCommit.typeUrl || typeof o.height === "bigint" && typeof o.round === "number" && BlockID.is(o.blockId) && Array.isArray(o.extendedSignatures) && (!o.extendedSignatures.length || ExtendedCommitSig.is(o.extendedSignatures[0]))); }, isAmino(o) { return o && (o.$typeUrl === ExtendedCommit.typeUrl || typeof o.height === "bigint" && typeof o.round === "number" && BlockID.isAmino(o.block_id) && Array.isArray(o.extended_signatures) && (!o.extended_signatures.length || ExtendedCommitSig.isAmino(o.extended_signatures[0]))); }, encode(message, writer = BinaryWriter.create()) { if (message.height !== BigInt(0)) { writer.uint32(8).int64(message.height); } if (message.round !== 0) { writer.uint32(16).int32(message.round); } if (message.blockId !== undefined) { BlockID.encode(message.blockId, writer.uint32(26).fork()).ldelim(); } for (const v of message.extendedSignatures) { ExtendedCommitSig.encode(v, writer.uint32(34).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseExtendedCommit(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.height = reader.int64(); break; case 2: message.round = reader.int32(); break; case 3: message.blockId = BlockID.decode(reader, reader.uint32()); break; case 4: message.extendedSignatures.push(ExtendedCommitSig.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseExtendedCommit(); message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0); message.round = object.round ?? 0; message.blockId = object.blockId !== undefined && object.blockId !== null ? BlockID.fromPartial(object.blockId) : undefined; message.extendedSignatures = object.extendedSignatures?.map(e => ExtendedCommitSig.fromPartial(e)) || []; return message; }, fromAmino(object) { const message = createBaseExtendedCommit(); if (object.height !== undefined && object.height !== null) { message.height = BigInt(object.height); } if (object.round !== undefined && object.round !== null) { message.round = object.round; } if (object.block_id !== undefined && object.block_id !== null) { message.blockId = BlockID.fromAmino(object.block_id); } message.extendedSignatures = object.extended_signatures?.map(e => ExtendedCommitSig.fromAmino(e)) || []; return message; }, toAmino(message) { const obj = {}; obj.height = message.height !== BigInt(0) ? message.height?.toString() : undefined; obj.round = message.round === 0 ? undefined : message.round; obj.block_id = message.blockId ? BlockID.toAmino(message.blockId) : undefined; if (message.extendedSignatures) { obj.extended_signatures = message.extendedSignatures.map(e => e ? ExtendedCommitSig.toAmino(e) : undefined); } else { obj.extended_signatures = message.extendedSignatures; } return obj; }, fromAminoMsg(object) { return ExtendedCommit.fromAmino(object.value); }, fromProtoMsg(message) { return ExtendedCommit.decode(message.value); }, toProto(message) { return ExtendedCommit.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/tendermint.types.ExtendedCommit", value: ExtendedCommit.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(ExtendedCommit.typeUrl)) { return; } BlockID.registerTypeUrl(); ExtendedCommitSig.registerTypeUrl(); } }; function createBaseExtendedCommitSig()