"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StoreKVPair = exports.BlockMetadata_DeliverTx = exports.BlockMetadata = void 0;
var _types = require("../../../../tendermint/abci/types");
var _binary = require("../../../../binary");
var _helpers = require("../../../../helpers");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * StoreKVPair is a KVStore KVPair used for listening to state changes (Sets and Deletes)
 * It optionally includes the StoreKey for the originating KVStore and a Boolean flag to distinguish between Sets and
 * Deletes
 * 
 * Since: cosmos-sdk 0.43
 */

/**
 * StoreKVPair is a KVStore KVPair used for listening to state changes (Sets and Deletes)
 * It optionally includes the StoreKey for the originating KVStore and a Boolean flag to distinguish between Sets and
 * Deletes
 * 
 * Since: cosmos-sdk 0.43
 */

/**
 * StoreKVPair is a KVStore KVPair used for listening to state changes (Sets and Deletes)
 * It optionally includes the StoreKey for the originating KVStore and a Boolean flag to distinguish between Sets and
 * Deletes
 * 
 * Since: cosmos-sdk 0.43
 */

/**
 * BlockMetadata contains all the abci event data of a block
 * the file streamer dump them into files together with the state changes.
 */

/**
 * BlockMetadata contains all the abci event data of a block
 * the file streamer dump them into files together with the state changes.
 */

/**
 * BlockMetadata contains all the abci event data of a block
 * the file streamer dump them into files together with the state changes.
 */

/** DeliverTx encapulate deliver tx request and response. */

/** DeliverTx encapulate deliver tx request and response. */

/** DeliverTx encapulate deliver tx request and response. */

function createBaseStoreKVPair() {
  return {
    storeKey: "",
    "delete": false,
    key: new Uint8Array(),
    value: new Uint8Array()
  };
}
var StoreKVPair = exports.StoreKVPair = {
  typeUrl: "/cosmos.base.store.v1beta1.StoreKVPair",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.storeKey !== "") {
      writer.uint32(10).string(message.storeKey);
    }
    if (message["delete"] === true) {
      writer.uint32(16).bool(message["delete"]);
    }
    if (message.key.length !== 0) {
      writer.uint32(26).bytes(message.key);
    }
    if (message.value.length !== 0) {
      writer.uint32(34).bytes(message.value);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      storeKey: (0, _helpers.isSet)(object.storeKey) ? String(object.storeKey) : "",
      "delete": (0, _helpers.isSet)(object["delete"]) ? Boolean(object["delete"]) : false,
      key: (0, _helpers.isSet)(object.key) ? (0, _helpers.bytesFromBase64)(object.key) : new Uint8Array(),
      value: (0, _helpers.isSet)(object.value) ? (0, _helpers.bytesFromBase64)(object.value) : new Uint8Array()
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$storeKey, _object$delete, _object$key, _object$value;
    var message = createBaseStoreKVPair();
    message.storeKey = (_object$storeKey = object.storeKey) !== null && _object$storeKey !== void 0 ? _object$storeKey : "";
    message["delete"] = (_object$delete = object["delete"]) !== null && _object$delete !== void 0 ? _object$delete : false;
    message.key = (_object$key = object.key) !== null && _object$key !== void 0 ? _object$key : new Uint8Array();
    message.value = (_object$value = object.value) !== null && _object$value !== void 0 ? _object$value : new Uint8Array();
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseStoreKVPair();
    if (object.store_key !== undefined && object.store_key !== null) {
      message.storeKey = object.store_key;
    }
    if (object["delete"] !== undefined && object["delete"] !== null) {
      message["delete"] = object["delete"];
    }
    if (object.key !== undefined && object.key !== null) {
      message.key = (0, _helpers.bytesFromBase64)(object.key);
    }
    if (object.value !== undefined && object.value !== null) {
      message.value = (0, _helpers.bytesFromBase64)(object.value);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.store_key = message.storeKey === "" ? undefined : message.storeKey;
    obj["delete"] = message["delete"] === false ? undefined : message["delete"];
    obj.key = message.key ? (0, _helpers.base64FromBytes)(message.key) : undefined;
    obj.value = message.value ? (0, _helpers.base64FromBytes)(message.value) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return StoreKVPair.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/StoreKVPair",
      value: StoreKVPair.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return StoreKVPair.decode(message.value);
  },
  toProto: function toProto(message) {
    return StoreKVPair.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.base.store.v1beta1.StoreKVPair",
      value: StoreKVPair.encode(message).finish()
    };
  }
};
function createBaseBlockMetadata() {
  return {
    requestBeginBlock: undefined,
    responseBeginBlock: undefined,
    deliverTxs: [],
    requestEndBlock: undefined,
    responseEndBlock: undefined,
    responseCommit: undefined
  };
}
var BlockMetadata = exports.BlockMetadata = {
  typeUrl: "/cosmos.base.store.v1beta1.BlockMetadata",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.requestBeginBlock !== undefined) {
      _types.RequestBeginBlock.encode(message.requestBeginBlock, writer.uint32(10).fork()).ldelim();
    }
    if (message.responseBeginBlock !== undefined) {
      _types.ResponseBeginBlock.encode(message.responseBeginBlock, writer.uint32(18).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.deliverTxs),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        BlockMetadata_DeliverTx.encode(v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.requestEndBlock !== undefined) {
      _types.RequestEndBlock.encode(message.requestEndBlock, writer.uint32(34).fork()).ldelim();
    }
    if (message.responseEndBlock !== undefined) {
      _types.ResponseEndBlock.encode(message.responseEndBlock, writer.uint32(42).fork()).ldelim();
    }
    if (message.responseCommit !== undefined) {
      _types.ResponseCommit.encode(message.responseCommit, writer.uint32(50).fork()).ldelim();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      requestBeginBlock: (0, _helpers.isSet)(object.requestBeginBlock) ? _types.RequestBeginBlock.fromJSON(object.requestBeginBlock) : undefined,
      responseBeginBlock: (0, _helpers.isSet)(object.responseBeginBlock) ? _types.ResponseBeginBlock.fromJSON(object.responseBeginBlock) : undefined,
      deliverTxs: Array.isArray(object === null || object === void 0 ? void 0 : object.deliverTxs) ? object.deliverTxs.map(function (e) {
        return BlockMetadata_DeliverTx.fromJSON(e);
      }) : [],
      requestEndBlock: (0, _helpers.isSet)(object.requestEndBlock) ? _types.RequestEndBlock.fromJSON(object.requestEndBlock) : undefined,
      responseEndBlock: (0, _helpers.isSet)(object.responseEndBlock) ? _types.ResponseEndBlock.fromJSON(object.responseEndBlock) : undefined,
      responseCommit: (0, _helpers.isSet)(object.responseCommit) ? _types.ResponseCommit.fromJSON(object.responseCommit) : undefined
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$deliverTxs;
    var message = createBaseBlockMetadata();
    message.requestBeginBlock = object.requestBeginBlock !== undefined && object.requestBeginBlock !== null ? _types.RequestBeginBlock.fromPartial(object.requestBeginBlock) : undefined;
    message.responseBeginBlock = object.responseBeginBlock !== undefined && object.responseBeginBlock !== null ? _types.ResponseBeginBlock.fromPartial(object.responseBeginBlock) : undefined;
    message.deliverTxs = ((_object$deliverTxs = object.deliverTxs) === null || _object$deliverTxs === void 0 ? void 0 : _object$deliverTxs.map(function (e) {
      return BlockMetadata_DeliverTx.fromPartial(e);
    })) || [];
    message.requestEndBlock = object.requestEndBlock !== undefined && object.requestEndBlock !== null ? _types.RequestEndBlock.fromPartial(object.requestEndBlock) : undefined;
    message.responseEndBlock = object.responseEndBlock !== undefined && object.responseEndBlock !== null ? _types.ResponseEndBlock.fromPartial(object.responseEndBlock) : undefined;
    message.responseCommit = object.responseCommit !== undefined && object.responseCommit !== null ? _types.ResponseCommit.fromPartial(object.responseCommit) : undefined;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$deliver_txs;
    var message = createBaseBlockMetadata();
    if (object.request_begin_block !== undefined && object.request_begin_block !== null) {
      message.requestBeginBlock = _types.RequestBeginBlock.fromAmino(object.request_begin_block);
    }
    if (object.response_begin_block !== undefined && object.response_begin_block !== null) {
      message.responseBeginBlock = _types.ResponseBeginBlock.fromAmino(object.response_begin_block);
    }
    message.deliverTxs = ((_object$deliver_txs = object.deliver_txs) === null || _object$deliver_txs === void 0 ? void 0 : _object$deliver_txs.map(function (e) {
      return BlockMetadata_DeliverTx.fromAmino(e);
    })) || [];
    if (object.request_end_block !== undefined && object.request_end_block !== null) {
      message.requestEndBlock = _types.RequestEndBlock.fromAmino(object.request_end_block);
    }
    if (object.response_end_block !== undefined && object.response_end_block !== null) {
      message.responseEndBlock = _types.ResponseEndBlock.fromAmino(object.response_end_block);
    }
    if (object.response_commit !== undefined && object.response_commit !== null) {
      message.responseCommit = _types.ResponseCommit.fromAmino(object.response_commit);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.request_begin_block = message.requestBeginBlock ? _types.RequestBeginBlock.toAmino(message.requestBeginBlock) : undefined;
    obj.response_begin_block = message.responseBeginBlock ? _types.ResponseBeginBlock.toAmino(message.responseBeginBlock) : undefined;
    if (message.deliverTxs) {
      obj.deliver_txs = message.deliverTxs.map(function (e) {
        return e ? BlockMetadata_DeliverTx.toAmino(e) : undefined;
      });
    } else {
      obj.deliver_txs = message.deliverTxs;
    }
    obj.request_end_block = message.requestEndBlock ? _types.RequestEndBlock.toAmino(message.requestEndBlock) : undefined;
    obj.response_end_block = message.responseEndBlock ? _types.ResponseEndBlock.toAmino(message.responseEndBlock) : undefined;
    obj.response_commit = message.responseCommit ? _types.ResponseCommit.toAmino(message.responseCommit) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return BlockMetadata.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/BlockMetadata",
      value: BlockMetadata.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return BlockMetadata.decode(message.value);
  },
  toProto: function toProto(message) {
    return BlockMetadata.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.base.store.v1beta1.BlockMetadata",
      value: BlockMetadata.encode(message).finish()
    };
  }
};
function createBaseBlockMetadata_DeliverTx() {
  return {
    request: undefined,
    response: undefined
  };
}
var BlockMetadata_DeliverTx = exports.BlockMetadata_DeliverTx = {
  typeUrl: "/cosmos.base.store.v1beta1.DeliverTx",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.request !== undefined) {
      _types.RequestDeliverTx.encode(message.request, writer.uint32(10).fork()).ldelim();
    }
    if (message.response !== undefined) {
      _types.ResponseDeliverTx.encode(message.response, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      request: (0, _helpers.isSet)(object.request) ? _types.RequestDeliverTx.fromJSON(object.request) : undefined,
      response: (0, _helpers.isSet)(object.response) ? _types.ResponseDeliverTx.fromJSON(object.response) : undefined
    };
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseBlockMetadata_DeliverTx();
    message.request = object.request !== undefined && object.request !== null ? _types.RequestDeliverTx.fromPartial(object.request) : undefined;
    message.response = object.response !== undefined && object.response !== null ? _types.ResponseDeliverTx.fromPartial(object.response) : undefined;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseBlockMetadata_DeliverTx();
    if (object.request !== undefined && object.request !== null) {
      message.request = _types.RequestDeliverTx.fromAmino(object.request);
    }
    if (object.response !== undefined && object.response !== null) {
      message.response = _types.ResponseDeliverTx.fromAmino(object.response);
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.request = message.request ? _types.RequestDeliverTx.toAmino(message.request) : undefined;
    obj.response = message.response ? _types.ResponseDeliverTx.toAmino(message.response) : undefined;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return BlockMetadata_DeliverTx.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/DeliverTx",
      value: BlockMetadata_DeliverTx.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return BlockMetadata_DeliverTx.decode(message.value);
  },
  toProto: function toProto(message) {
    return BlockMetadata_DeliverTx.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.base.store.v1beta1.DeliverTx",
      value: BlockMetadata_DeliverTx.encode(message).finish()
    };
  }
};