"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Header = exports.Block = void 0;
var _types = require("../../../../tendermint/types/types");
var _evidence = require("../../../../tendermint/types/evidence");
var _types2 = require("../../../../tendermint/version/types");
var _timestamp = require("../../../../google/protobuf/timestamp");
var _binary = require("../../../../binary");
var _helpers = require("../../../../helpers");
/**
 * Block is tendermint type Block, with the Header proposer address
 * field converted to bech32 string.
 */

/**
 * Block is tendermint type Block, with the Header proposer address
 * field converted to bech32 string.
 */

/**
 * Block is tendermint type Block, with the Header proposer address
 * field converted to bech32 string.
 */

/** Header defines the structure of a Tendermint block header. */

/** Header defines the structure of a Tendermint block header. */

/** Header defines the structure of a Tendermint block header. */

function createBaseBlock() {
  return {
    header: Header.fromPartial({}),
    data: _types.Data.fromPartial({}),
    evidence: _evidence.EvidenceList.fromPartial({}),
    lastCommit: undefined
  };
}
var Block = exports.Block = {
  typeUrl: "/cosmos.base.tendermint.v1beta1.Block",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.header !== undefined) {
      Header.encode(message.header, writer.uint32(10).fork()).ldelim();
    }
    if (message.data !== undefined) {
      _types.Data.encode(message.data, writer.uint32(18).fork()).ldelim();
    }
    if (message.evidence !== undefined) {
      _evidence.EvidenceList.encode(message.evidence, writer.uint32(26).fork()).ldelim();
    }
    if (message.lastCommit !== undefined) {
      _types.Commit.encode(message.lastCommit, writer.uint32(34).fork()).ldelim();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      header: (0, _helpers.isSet)(object.header) ? Header.fromJSON(object.header) : undefined,
      data: (0, _helpers.isSet)(object.data) ? _types.Data.fromJSON(object.data) : undefined,
      evidence: (0, _helpers.isSet)(object.evidence) ? _evidence.EvidenceList.fromJSON(object.evidence) : undefined,
      lastCommit: (0, _helpers.isSet)(object.lastCommit) ? _types.Commit.fromJSON(object.lastCommit) : undefined
    };
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseBlock();
    message.header = object.header !== undefined && object.header !== null ? Header.fromPartial(object.header) : undefined;
    message.data = object.data !== undefined && object.data !== null ? _types.Data.fromPartial(object.data) : undefined;
    message.evidence = object.evidence !== undefined && object.evidence !== null ? _evidence.EvidenceList.fromPartial(object.evidence) : undefined;
    message.lastCommit = object.lastCommit !== undefined && object.lastCommit !== null ? _types.Commit.fromPartial(object.lastCommit) : undefined;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseBlock();
    if (object.header !== undefined && object.header !== null) {
      message.header = Header.fromAmino(object.header);
    }
    if (object.data !== undefined && object.data !== null) {
      message.data = _types.Data.fromAmino(object.data);
    }
    if (object.evidence !== undefined && object.evidence !== null) {
      message.evidence = _evidence.EvidenceList.fromAmino(object.evidence);
    }
    if (object.last_commit !== undefined && object.last_commit !== null) {
      message.lastCommit = _types.Commit.fromAmino(object.last_commit);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.header = message.header ? Header.toAmino(message.header) : undefined;
    obj.data = message.data ? _types.Data.toAmino(message.data) : undefined;
    obj.evidence = message.evidence ? _evidence.EvidenceList.toAmino(message.evidence) : undefined;
    obj.last_commit = message.lastCommit ? _types.Commit.toAmino(message.lastCommit) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Block.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/Block",
      value: Block.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Block.decode(message.value);
  },
  toProto: function toProto(message) {
    return Block.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.base.tendermint.v1beta1.Block",
      value: Block.encode(message).finish()
    };
  }
};
function createBaseHeader() {
  return {
    version: _types2.Consensus.fromPartial({}),
    chainId: "",
    height: BigInt(0),
    time: _timestamp.Timestamp.fromPartial({}),
    lastBlockId: _types.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: ""
  };
}
var Header = exports.Header = {
  typeUrl: "/cosmos.base.tendermint.v1beta1.Header",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.version !== undefined) {
      _types2.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.Timestamp.encode(message.time, writer.uint32(34).fork()).ldelim();
    }
    if (message.lastBlockId !== undefined) {
      _types.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 !== "") {
      writer.uint32(114).string(message.proposerAddress);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      version: (0, _helpers.isSet)(object.version) ? _types2.Consensus.fromJSON(object.version) : undefined,
      chainId: (0, _helpers.isSet)(object.chainId) ? String(object.chainId) : "",
      height: (0, _helpers.isSet)(object.height) ? BigInt(object.height.toString()) : BigInt(0),
      time: (0, _helpers.isSet)(object.time) ? (0, _helpers.fromJsonTimestamp)(object.time) : undefined,
      lastBlockId: (0, _helpers.isSet)(object.lastBlockId) ? _types.BlockID.fromJSON(object.lastBlockId) : undefined,
      lastCommitHash: (0, _helpers.isSet)(object.lastCommitHash) ? (0, _helpers.bytesFromBase64)(object.lastCommitHash) : new Uint8Array(),
      dataHash: (0, _helpers.isSet)(object.dataHash) ? (0, _helpers.bytesFromBase64)(object.dataHash) : new Uint8Array(),
      validatorsHash: (0, _helpers.isSet)(object.validatorsHash) ? (0, _helpers.bytesFromBase64)(object.validatorsHash) : new Uint8Array(),
      nextValidatorsHash: (0, _helpers.isSet)(object.nextValidatorsHash) ? (0, _helpers.bytesFromBase64)(object.nextValidatorsHash) : new Uint8Array(),
      consensusHash: (0, _helpers.isSet)(object.consensusHash) ? (0, _helpers.bytesFromBase64)(object.consensusHash) : new Uint8Array(),
      appHash: (0, _helpers.isSet)(object.appHash) ? (0, _helpers.bytesFromBase64)(object.appHash) : new Uint8Array(),
      lastResultsHash: (0, _helpers.isSet)(object.lastResultsHash) ? (0, _helpers.bytesFromBase64)(object.lastResultsHash) : new Uint8Array(),
      evidenceHash: (0, _helpers.isSet)(object.evidenceHash) ? (0, _helpers.bytesFromBase64)(object.evidenceHash) : new Uint8Array(),
      proposerAddress: (0, _helpers.isSet)(object.proposerAddress) ? String(object.proposerAddress) : ""
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$chainId, _object$lastCommitHas, _object$dataHash, _object$validatorsHas, _object$nextValidator, _object$consensusHash, _object$appHash, _object$lastResultsHa, _object$evidenceHash, _object$proposerAddre;
    var message = createBaseHeader();
    message.version = object.version !== undefined && object.version !== null ? _types2.Consensus.fromPartial(object.version) : undefined;
    message.chainId = (_object$chainId = object.chainId) !== null && _object$chainId !== void 0 ? _object$chainId : "";
    message.height = object.height !== undefined && object.height !== null ? BigInt(object.height.toString()) : BigInt(0);
    message.time = object.time !== undefined && object.time !== null ? _timestamp.Timestamp.fromPartial(object.time) : undefined;
    message.lastBlockId = object.lastBlockId !== undefined && object.lastBlockId !== null ? _types.BlockID.fromPartial(object.lastBlockId) : undefined;
    message.lastCommitHash = (_object$lastCommitHas = object.lastCommitHash) !== null && _object$lastCommitHas !== void 0 ? _object$lastCommitHas : new Uint8Array();
    message.dataHash = (_object$dataHash = object.dataHash) !== null && _object$dataHash !== void 0 ? _object$dataHash : new Uint8Array();
    message.validatorsHash = (_object$validatorsHas = object.validatorsHash) !== null && _object$validatorsHas !== void 0 ? _object$validatorsHas : new Uint8Array();
    message.nextValidatorsHash = (_object$nextValidator = object.nextValidatorsHash) !== null && _object$nextValidator !== void 0 ? _object$nextValidator : new Uint8Array();
    message.consensusHash = (_object$consensusHash = object.consensusHash) !== null && _object$consensusHash !== void 0 ? _object$consensusHash : new Uint8Array();
    message.appHash = (_object$appHash = object.appHash) !== null && _object$appHash !== void 0 ? _object$appHash : new Uint8Array();
    message.lastResultsHash = (_object$lastResultsHa = object.lastResultsHash) !== null && _object$lastResultsHa !== void 0 ? _object$lastResultsHa : new Uint8Array();
    message.evidenceHash = (_object$evidenceHash = object.evidenceHash) !== null && _object$evidenceHash !== void 0 ? _object$evidenceHash : new Uint8Array();
    message.proposerAddress = (_object$proposerAddre = object.proposerAddress) !== null && _object$proposerAddre !== void 0 ? _object$proposerAddre : "";
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseHeader();
    if (object.version !== undefined && object.version !== null) {
      message.version = _types2.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 = _timestamp.Timestamp.fromAmino(object.time);
    }
    if (object.last_block_id !== undefined && object.last_block_id !== null) {
      message.lastBlockId = _types.BlockID.fromAmino(object.last_block_id);
    }
    if (object.last_commit_hash !== undefined && object.last_commit_hash !== null) {
      message.lastCommitHash = (0, _helpers.bytesFromBase64)(object.last_commit_hash);
    }
    if (object.data_hash !== undefined && object.data_hash !== null) {
      message.dataHash = (0, _helpers.bytesFromBase64)(object.data_hash);
    }
    if (object.validators_hash !== undefined && object.validators_hash !== null) {
      message.validatorsHash = (0, _helpers.bytesFromBase64)(object.validators_hash);
    }
    if (object.next_validators_hash !== undefined && object.next_validators_hash !== null) {
      message.nextValidatorsHash = (0, _helpers.bytesFromBase64)(object.next_validators_hash);
    }
    if (object.consensus_hash !== undefined && object.consensus_hash !== null) {
      message.consensusHash = (0, _helpers.bytesFromBase64)(object.consensus_hash);
    }
    if (object.app_hash !== undefined && object.app_hash !== null) {
      message.appHash = (0, _helpers.bytesFromBase64)(object.app_hash);
    }
    if (object.last_results_hash !== undefined && object.last_results_hash !== null) {
      message.lastResultsHash = (0, _helpers.bytesFromBase64)(object.last_results_hash);
    }
    if (object.evidence_hash !== undefined && object.evidence_hash !== null) {
      message.evidenceHash = (0, _helpers.bytesFromBase64)(object.evidence_hash);
    }
    if (object.proposer_address !== undefined && object.proposer_address !== null) {
      message.proposerAddress = object.proposer_address;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.version = message.version ? _types2.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.Timestamp.toAmino(message.time) : undefined;
    obj.last_block_id = message.lastBlockId ? _types.BlockID.toAmino(message.lastBlockId) : undefined;
    obj.last_commit_hash = message.lastCommitHash ? (0, _helpers.base64FromBytes)(message.lastCommitHash) : undefined;
    obj.data_hash = message.dataHash ? (0, _helpers.base64FromBytes)(message.dataHash) : undefined;
    obj.validators_hash = message.validatorsHash ? (0, _helpers.base64FromBytes)(message.validatorsHash) : undefined;
    obj.next_validators_hash = message.nextValidatorsHash ? (0, _helpers.base64FromBytes)(message.nextValidatorsHash) : undefined;
    obj.consensus_hash = message.consensusHash ? (0, _helpers.base64FromBytes)(message.consensusHash) : undefined;
    obj.app_hash = message.appHash ? (0, _helpers.base64FromBytes)(message.appHash) : undefined;
    obj.last_results_hash = message.lastResultsHash ? (0, _helpers.base64FromBytes)(message.lastResultsHash) : undefined;
    obj.evidence_hash = message.evidenceHash ? (0, _helpers.base64FromBytes)(message.evidenceHash) : undefined;
    obj.proposer_address = message.proposerAddress === "" ? undefined : message.proposerAddress;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Header.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/Header",
      value: Header.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Header.decode(message.value);
  },
  toProto: function toProto(message) {
    return Header.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.base.tendermint.v1beta1.Header",
      value: Header.encode(message).finish()
    };
  }
};