"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Sequence = exports.GenesisState = exports.Contract = exports.Code = void 0;
var _types = require("./types");
var _helpers = require("../../../helpers");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } //@ts-nocheck
/** GenesisState - genesis state of x/wasm */

/** GenesisState - genesis state of x/wasm */

/** Code struct encompasses CodeInfo and CodeBytes */

/** Code struct encompasses CodeInfo and CodeBytes */

/** Contract struct encompasses ContractAddress, ContractInfo, and ContractState */

/** Contract struct encompasses ContractAddress, ContractInfo, and ContractState */

/** Sequence key and value of an id generation counter */

/** Sequence key and value of an id generation counter */

function createBaseGenesisState() {
  return {
    params: undefined,
    codes: [],
    contracts: [],
    sequences: []
  };
}
var GenesisState = exports.GenesisState = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.params !== undefined) {
      _types.Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.codes),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        Code.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.contracts),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        Contract.encode(_v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.sequences),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        Sequence.encode(_v2, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseGenesisState();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = _types.Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.codes.push(Code.decode(reader, reader.uint32()));
          break;
        case 3:
          message.contracts.push(Contract.decode(reader, reader.uint32()));
          break;
        case 4:
          message.sequences.push(Sequence.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      params: (0, _helpers.isSet)(object.params) ? _types.Params.fromJSON(object.params) : undefined,
      codes: Array.isArray(object === null || object === void 0 ? void 0 : object.codes) ? object.codes.map(function (e) {
        return Code.fromJSON(e);
      }) : [],
      contracts: Array.isArray(object === null || object === void 0 ? void 0 : object.contracts) ? object.contracts.map(function (e) {
        return Contract.fromJSON(e);
      }) : [],
      sequences: Array.isArray(object === null || object === void 0 ? void 0 : object.sequences) ? object.sequences.map(function (e) {
        return Sequence.fromJSON(e);
      }) : []
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.params !== undefined && (obj.params = message.params ? _types.Params.toJSON(message.params) : undefined);
    if (message.codes) {
      obj.codes = message.codes.map(function (e) {
        return e ? Code.toJSON(e) : undefined;
      });
    } else {
      obj.codes = [];
    }
    if (message.contracts) {
      obj.contracts = message.contracts.map(function (e) {
        return e ? Contract.toJSON(e) : undefined;
      });
    } else {
      obj.contracts = [];
    }
    if (message.sequences) {
      obj.sequences = message.sequences.map(function (e) {
        return e ? Sequence.toJSON(e) : undefined;
      });
    } else {
      obj.sequences = [];
    }
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$codes, _object$contracts, _object$sequences;
    var message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? _types.Params.fromPartial(object.params) : undefined;
    message.codes = ((_object$codes = object.codes) === null || _object$codes === void 0 ? void 0 : _object$codes.map(function (e) {
      return Code.fromPartial(e);
    })) || [];
    message.contracts = ((_object$contracts = object.contracts) === null || _object$contracts === void 0 ? void 0 : _object$contracts.map(function (e) {
      return Contract.fromPartial(e);
    })) || [];
    message.sequences = ((_object$sequences = object.sequences) === null || _object$sequences === void 0 ? void 0 : _object$sequences.map(function (e) {
      return Sequence.fromPartial(e);
    })) || [];
    return message;
  }
};
function createBaseCode() {
  return {
    codeId: _helpers.Long.UZERO,
    codeInfo: undefined,
    codeBytes: new Uint8Array(),
    pinned: false
  };
}
var Code = exports.Code = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (!message.codeId.isZero()) {
      writer.uint32(8).uint64(message.codeId);
    }
    if (message.codeInfo !== undefined) {
      _types.CodeInfo.encode(message.codeInfo, writer.uint32(18).fork()).ldelim();
    }
    if (message.codeBytes.length !== 0) {
      writer.uint32(26).bytes(message.codeBytes);
    }
    if (message.pinned === true) {
      writer.uint32(32).bool(message.pinned);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseCode();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.codeId = reader.uint64();
          break;
        case 2:
          message.codeInfo = _types.CodeInfo.decode(reader, reader.uint32());
          break;
        case 3:
          message.codeBytes = reader.bytes();
          break;
        case 4:
          message.pinned = reader.bool();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      codeId: (0, _helpers.isSet)(object.codeId) ? _helpers.Long.fromValue(object.codeId) : _helpers.Long.UZERO,
      codeInfo: (0, _helpers.isSet)(object.codeInfo) ? _types.CodeInfo.fromJSON(object.codeInfo) : undefined,
      codeBytes: (0, _helpers.isSet)(object.codeBytes) ? (0, _helpers.bytesFromBase64)(object.codeBytes) : new Uint8Array(),
      pinned: (0, _helpers.isSet)(object.pinned) ? Boolean(object.pinned) : false
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.codeId !== undefined && (obj.codeId = (message.codeId || _helpers.Long.UZERO).toString());
    message.codeInfo !== undefined && (obj.codeInfo = message.codeInfo ? _types.CodeInfo.toJSON(message.codeInfo) : undefined);
    message.codeBytes !== undefined && (obj.codeBytes = (0, _helpers.base64FromBytes)(message.codeBytes !== undefined ? message.codeBytes : new Uint8Array()));
    message.pinned !== undefined && (obj.pinned = message.pinned);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$codeBytes, _object$pinned;
    var message = createBaseCode();
    message.codeId = object.codeId !== undefined && object.codeId !== null ? _helpers.Long.fromValue(object.codeId) : _helpers.Long.UZERO;
    message.codeInfo = object.codeInfo !== undefined && object.codeInfo !== null ? _types.CodeInfo.fromPartial(object.codeInfo) : undefined;
    message.codeBytes = (_object$codeBytes = object.codeBytes) !== null && _object$codeBytes !== void 0 ? _object$codeBytes : new Uint8Array();
    message.pinned = (_object$pinned = object.pinned) !== null && _object$pinned !== void 0 ? _object$pinned : false;
    return message;
  }
};
function createBaseContract() {
  return {
    contractAddress: "",
    contractInfo: undefined,
    contractState: [],
    contractCodeHistory: []
  };
}
var Contract = exports.Contract = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.contractAddress !== "") {
      writer.uint32(10).string(message.contractAddress);
    }
    if (message.contractInfo !== undefined) {
      _types.ContractInfo.encode(message.contractInfo, writer.uint32(18).fork()).ldelim();
    }
    var _iterator4 = _createForOfIteratorHelper(message.contractState),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var v = _step4.value;
        _types.Model.encode(v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.contractCodeHistory),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v3 = _step5.value;
        _types.ContractCodeHistoryEntry.encode(_v3, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseContract();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.contractAddress = reader.string();
          break;
        case 2:
          message.contractInfo = _types.ContractInfo.decode(reader, reader.uint32());
          break;
        case 3:
          message.contractState.push(_types.Model.decode(reader, reader.uint32()));
          break;
        case 4:
          message.contractCodeHistory.push(_types.ContractCodeHistoryEntry.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      contractAddress: (0, _helpers.isSet)(object.contractAddress) ? String(object.contractAddress) : "",
      contractInfo: (0, _helpers.isSet)(object.contractInfo) ? _types.ContractInfo.fromJSON(object.contractInfo) : undefined,
      contractState: Array.isArray(object === null || object === void 0 ? void 0 : object.contractState) ? object.contractState.map(function (e) {
        return _types.Model.fromJSON(e);
      }) : [],
      contractCodeHistory: Array.isArray(object === null || object === void 0 ? void 0 : object.contractCodeHistory) ? object.contractCodeHistory.map(function (e) {
        return _types.ContractCodeHistoryEntry.fromJSON(e);
      }) : []
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.contractAddress !== undefined && (obj.contractAddress = message.contractAddress);
    message.contractInfo !== undefined && (obj.contractInfo = message.contractInfo ? _types.ContractInfo.toJSON(message.contractInfo) : undefined);
    if (message.contractState) {
      obj.contractState = message.contractState.map(function (e) {
        return e ? _types.Model.toJSON(e) : undefined;
      });
    } else {
      obj.contractState = [];
    }
    if (message.contractCodeHistory) {
      obj.contractCodeHistory = message.contractCodeHistory.map(function (e) {
        return e ? _types.ContractCodeHistoryEntry.toJSON(e) : undefined;
      });
    } else {
      obj.contractCodeHistory = [];
    }
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$contractAddre, _object$contractState, _object$contractCodeH;
    var message = createBaseContract();
    message.contractAddress = (_object$contractAddre = object.contractAddress) !== null && _object$contractAddre !== void 0 ? _object$contractAddre : "";
    message.contractInfo = object.contractInfo !== undefined && object.contractInfo !== null ? _types.ContractInfo.fromPartial(object.contractInfo) : undefined;
    message.contractState = ((_object$contractState = object.contractState) === null || _object$contractState === void 0 ? void 0 : _object$contractState.map(function (e) {
      return _types.Model.fromPartial(e);
    })) || [];
    message.contractCodeHistory = ((_object$contractCodeH = object.contractCodeHistory) === null || _object$contractCodeH === void 0 ? void 0 : _object$contractCodeH.map(function (e) {
      return _types.ContractCodeHistoryEntry.fromPartial(e);
    })) || [];
    return message;
  }
};
function createBaseSequence() {
  return {
    idKey: new Uint8Array(),
    value: _helpers.Long.UZERO
  };
}
var Sequence = exports.Sequence = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.idKey.length !== 0) {
      writer.uint32(10).bytes(message.idKey);
    }
    if (!message.value.isZero()) {
      writer.uint32(16).uint64(message.value);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseSequence();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.idKey = reader.bytes();
          break;
        case 2:
          message.value = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      idKey: (0, _helpers.isSet)(object.idKey) ? (0, _helpers.bytesFromBase64)(object.idKey) : new Uint8Array(),
      value: (0, _helpers.isSet)(object.value) ? _helpers.Long.fromValue(object.value) : _helpers.Long.UZERO
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    message.idKey !== undefined && (obj.idKey = (0, _helpers.base64FromBytes)(message.idKey !== undefined ? message.idKey : new Uint8Array()));
    message.value !== undefined && (obj.value = (message.value || _helpers.Long.UZERO).toString());
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$idKey;
    var message = createBaseSequence();
    message.idKey = (_object$idKey = object.idKey) !== null && _object$idKey !== void 0 ? _object$idKey : new Uint8Array();
    message.value = object.value !== undefined && object.value !== null ? _helpers.Long.fromValue(object.value) : _helpers.Long.UZERO;
    return message;
  }
};