"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getContractData = exports.getContractCodes = exports.getContractCode = exports.getContractAddress = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _contract = require("./contract.constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var getContractCodes = exports.getContractCodes = function getContractCodes(chainNetwork, category) {
  return _contract.contracts.filter(function (contract) {
    return !category || contract.category === category;
  }).map(function (contract) {
    return {
      name: contract.name,
      code: contract.code[chainNetwork]
    };
  });
};
var getContractCode = exports.getContractCode = function getContractCode(chainNetwork, contractName) {
  var _contracts$find$code$, _contracts$find;
  return (_contracts$find$code$ = (_contracts$find = _contract.contracts.find(function (contract) {
    return contract.name === contractName;
  })) === null || _contracts$find === void 0 ? void 0 : _contracts$find.code[chainNetwork]) !== null && _contracts$find$code$ !== void 0 ? _contracts$find$code$ : -1;
};
var getContractAddress = exports.getContractAddress = function getContractAddress(chainNetwork, contractName) {
  var _contracts$find$addre, _contracts$find2;
  var addresses = (_contracts$find$addre = (_contracts$find2 = _contract.contracts.find(function (contract) {
    return contract.name === contractName;
  })) === null || _contracts$find2 === void 0 ? void 0 : _contracts$find2.address) !== null && _contracts$find$addre !== void 0 ? _contracts$find$addre : {};
  return addresses[chainNetwork];
};
var getContractData = exports.getContractData = function getContractData(chainNetwork, contractName) {
  var data = _contract.contracts.find(function (contract) {
    return contract.name === contractName;
  });
  return data !== null && data !== void 0 && data.code ? _objectSpread(_objectSpread({}, data), {}, {
    code: data.code[chainNetwork],
    address: data.address[chainNetwork]
  }) : undefined;
};