"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GenesisState = exports.CalldataRecord = void 0;
var _oracle = require("./oracle");
var _helpers = require("../../../helpers");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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; }
function createBaseGenesisState() {
  return {
    params: undefined,
    bandRelayers: [],
    bandPriceStates: [],
    priceFeedPriceStates: [],
    coinbasePriceStates: [],
    bandIbcPriceStates: [],
    bandIbcOracleRequests: [],
    bandIbcParams: undefined,
    bandIbcLatestClientId: _helpers.Long.UZERO,
    calldataRecords: [],
    bandIbcLatestRequestId: _helpers.Long.UZERO,
    chainlinkPriceStates: [],
    historicalPriceRecords: [],
    providerStates: []
  };
}
var GenesisState = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.params !== undefined) {
      _oracle.Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.bandRelayers),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        writer.uint32(18).string(v);
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.bandPriceStates),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        _oracle.BandPriceState.encode(_v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.priceFeedPriceStates),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        _oracle.PriceFeedState.encode(_v2, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(message.coinbasePriceStates),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        _oracle.CoinbasePriceState.encode(_v3, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.bandIbcPriceStates),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v4 = _step5.value;
        _oracle.BandPriceState.encode(_v4, writer.uint32(50).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var _iterator6 = _createForOfIteratorHelper(message.bandIbcOracleRequests),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var _v5 = _step6.value;
        _oracle.BandOracleRequest.encode(_v5, writer.uint32(58).fork()).ldelim();
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    if (message.bandIbcParams !== undefined) {
      _oracle.BandIBCParams.encode(message.bandIbcParams, writer.uint32(66).fork()).ldelim();
    }
    if (!message.bandIbcLatestClientId.isZero()) {
      writer.uint32(72).uint64(message.bandIbcLatestClientId);
    }
    var _iterator7 = _createForOfIteratorHelper(message.calldataRecords),
      _step7;
    try {
      for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
        var _v6 = _step7.value;
        CalldataRecord.encode(_v6, writer.uint32(82).fork()).ldelim();
      }
    } catch (err) {
      _iterator7.e(err);
    } finally {
      _iterator7.f();
    }
    if (!message.bandIbcLatestRequestId.isZero()) {
      writer.uint32(88).uint64(message.bandIbcLatestRequestId);
    }
    var _iterator8 = _createForOfIteratorHelper(message.chainlinkPriceStates),
      _step8;
    try {
      for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
        var _v7 = _step8.value;
        _oracle.ChainlinkPriceState.encode(_v7, writer.uint32(98).fork()).ldelim();
      }
    } catch (err) {
      _iterator8.e(err);
    } finally {
      _iterator8.f();
    }
    var _iterator9 = _createForOfIteratorHelper(message.historicalPriceRecords),
      _step9;
    try {
      for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
        var _v8 = _step9.value;
        _oracle.PriceRecords.encode(_v8, writer.uint32(106).fork()).ldelim();
      }
    } catch (err) {
      _iterator9.e(err);
    } finally {
      _iterator9.f();
    }
    var _iterator10 = _createForOfIteratorHelper(message.providerStates),
      _step10;
    try {
      for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
        var _v9 = _step10.value;
        _oracle.ProviderState.encode(_v9, writer.uint32(114).fork()).ldelim();
      }
    } catch (err) {
      _iterator10.e(err);
    } finally {
      _iterator10.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 = _oracle.Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.bandRelayers.push(reader.string());
          break;
        case 3:
          message.bandPriceStates.push(_oracle.BandPriceState.decode(reader, reader.uint32()));
          break;
        case 4:
          message.priceFeedPriceStates.push(_oracle.PriceFeedState.decode(reader, reader.uint32()));
          break;
        case 5:
          message.coinbasePriceStates.push(_oracle.CoinbasePriceState.decode(reader, reader.uint32()));
          break;
        case 6:
          message.bandIbcPriceStates.push(_oracle.BandPriceState.decode(reader, reader.uint32()));
          break;
        case 7:
          message.bandIbcOracleRequests.push(_oracle.BandOracleRequest.decode(reader, reader.uint32()));
          break;
        case 8:
          message.bandIbcParams = _oracle.BandIBCParams.decode(reader, reader.uint32());
          break;
        case 9:
          message.bandIbcLatestClientId = reader.uint64();
          break;
        case 10:
          message.calldataRecords.push(CalldataRecord.decode(reader, reader.uint32()));
          break;
        case 11:
          message.bandIbcLatestRequestId = reader.uint64();
          break;
        case 12:
          message.chainlinkPriceStates.push(_oracle.ChainlinkPriceState.decode(reader, reader.uint32()));
          break;
        case 13:
          message.historicalPriceRecords.push(_oracle.PriceRecords.decode(reader, reader.uint32()));
          break;
        case 14:
          message.providerStates.push(_oracle.ProviderState.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$bandRelayers, _object$bandPriceStat, _object$priceFeedPric, _object$coinbasePrice, _object$bandIbcPriceS, _object$bandIbcOracle, _object$calldataRecor, _object$chainlinkPric, _object$historicalPri, _object$providerState;
    var message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? _oracle.Params.fromPartial(object.params) : undefined;
    message.bandRelayers = ((_object$bandRelayers = object.bandRelayers) === null || _object$bandRelayers === void 0 ? void 0 : _object$bandRelayers.map(function (e) {
      return e;
    })) || [];
    message.bandPriceStates = ((_object$bandPriceStat = object.bandPriceStates) === null || _object$bandPriceStat === void 0 ? void 0 : _object$bandPriceStat.map(function (e) {
      return _oracle.BandPriceState.fromPartial(e);
    })) || [];
    message.priceFeedPriceStates = ((_object$priceFeedPric = object.priceFeedPriceStates) === null || _object$priceFeedPric === void 0 ? void 0 : _object$priceFeedPric.map(function (e) {
      return _oracle.PriceFeedState.fromPartial(e);
    })) || [];
    message.coinbasePriceStates = ((_object$coinbasePrice = object.coinbasePriceStates) === null || _object$coinbasePrice === void 0 ? void 0 : _object$coinbasePrice.map(function (e) {
      return _oracle.CoinbasePriceState.fromPartial(e);
    })) || [];
    message.bandIbcPriceStates = ((_object$bandIbcPriceS = object.bandIbcPriceStates) === null || _object$bandIbcPriceS === void 0 ? void 0 : _object$bandIbcPriceS.map(function (e) {
      return _oracle.BandPriceState.fromPartial(e);
    })) || [];
    message.bandIbcOracleRequests = ((_object$bandIbcOracle = object.bandIbcOracleRequests) === null || _object$bandIbcOracle === void 0 ? void 0 : _object$bandIbcOracle.map(function (e) {
      return _oracle.BandOracleRequest.fromPartial(e);
    })) || [];
    message.bandIbcParams = object.bandIbcParams !== undefined && object.bandIbcParams !== null ? _oracle.BandIBCParams.fromPartial(object.bandIbcParams) : undefined;
    message.bandIbcLatestClientId = object.bandIbcLatestClientId !== undefined && object.bandIbcLatestClientId !== null ? _helpers.Long.fromValue(object.bandIbcLatestClientId) : _helpers.Long.UZERO;
    message.calldataRecords = ((_object$calldataRecor = object.calldataRecords) === null || _object$calldataRecor === void 0 ? void 0 : _object$calldataRecor.map(function (e) {
      return CalldataRecord.fromPartial(e);
    })) || [];
    message.bandIbcLatestRequestId = object.bandIbcLatestRequestId !== undefined && object.bandIbcLatestRequestId !== null ? _helpers.Long.fromValue(object.bandIbcLatestRequestId) : _helpers.Long.UZERO;
    message.chainlinkPriceStates = ((_object$chainlinkPric = object.chainlinkPriceStates) === null || _object$chainlinkPric === void 0 ? void 0 : _object$chainlinkPric.map(function (e) {
      return _oracle.ChainlinkPriceState.fromPartial(e);
    })) || [];
    message.historicalPriceRecords = ((_object$historicalPri = object.historicalPriceRecords) === null || _object$historicalPri === void 0 ? void 0 : _object$historicalPri.map(function (e) {
      return _oracle.PriceRecords.fromPartial(e);
    })) || [];
    message.providerStates = ((_object$providerState = object.providerStates) === null || _object$providerState === void 0 ? void 0 : _object$providerState.map(function (e) {
      return _oracle.ProviderState.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.GenesisState = GenesisState;
function createBaseCalldataRecord() {
  return {
    clientId: _helpers.Long.UZERO,
    calldata: new Uint8Array()
  };
}
var CalldataRecord = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (!message.clientId.isZero()) {
      writer.uint32(8).uint64(message.clientId);
    }
    if (message.calldata.length !== 0) {
      writer.uint32(18).bytes(message.calldata);
    }
    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 = createBaseCalldataRecord();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.clientId = reader.uint64();
          break;
        case 2:
          message.calldata = reader.bytes();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$calldata;
    var message = createBaseCalldataRecord();
    message.clientId = object.clientId !== undefined && object.clientId !== null ? _helpers.Long.fromValue(object.clientId) : _helpers.Long.UZERO;
    message.calldata = (_object$calldata = object.calldata) !== null && _object$calldata !== void 0 ? _object$calldata : new Uint8Array();
    return message;
  }
};
exports.CalldataRecord = CalldataRecord;