'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.ABI_TYPES = undefined;var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;}; // Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
exports.

















parseAbiType = parseAbiType;var _lodash = require('lodash');var ARRAY_TYPE = 'ARRAY_TYPE';var ADDRESS_TYPE = 'ADDRESS_TYPE';var STRING_TYPE = 'STRING_TYPE';var BOOL_TYPE = 'BOOL_TYPE';var BYTES_TYPE = 'BYTES_TYPE';var INT_TYPE = 'INT_TYPE';var FIXED_TYPE = 'FIXED_TYPE';var ABI_TYPES = exports.ABI_TYPES = { ARRAY: ARRAY_TYPE, ADDRESS: ADDRESS_TYPE, STRING: STRING_TYPE, BOOL: BOOL_TYPE, BYTES: BYTES_TYPE, INT: INT_TYPE, FIXED: FIXED_TYPE };function parseAbiType(type) {
  var arrayRegex = /^(.+)\[(\d*)]$/;

  if (arrayRegex.test(type)) {
    var matches = arrayRegex.exec(type);

    var subtype = parseAbiType(matches[1]);
    var M = parseInt(matches[2]) || null;
    var defaultValue = !M ?
    [] :
    (0, _lodash.range)(M).map(function () {return subtype.default;});

    return {
      type: ARRAY_TYPE,
      subtype: subtype,
      length: M,
      default: defaultValue };

  }

  var lengthRegex = /^(u?int|bytes)(\d{1,3})$/;

  if (lengthRegex.test(type)) {
    var _matches = lengthRegex.exec(type);

    var _subtype = parseAbiType(_matches[1]);
    var length = parseInt(_matches[2]);

    return _extends({},
    _subtype, {
      length: length });

  }

  var fixedLengthRegex = /^(u?fixed)(\d{1,3})x(\d{1,3})$/;

  if (fixedLengthRegex.test(type)) {
    var _matches2 = fixedLengthRegex.exec(type);

    var _subtype2 = parseAbiType(_matches2[1]);
    var _M = parseInt(_matches2[2]);
    var N = parseInt(_matches2[3]);

    return _extends({},
    _subtype2, {
      M: _M, N: N });

  }

  if (type === 'string') {
    return {
      type: STRING_TYPE,
      default: '' };

  }

  if (type === 'bool') {
    return {
      type: BOOL_TYPE,
      default: false };

  }

  if (type === 'address') {
    return {
      type: ADDRESS_TYPE,
      default: '' };

  }

  if (type === 'bytes' || type === 'fixedBytes') {
    return {
      type: BYTES_TYPE,
      default: '0x' };

  }

  if (type === 'uint') {
    return {
      type: INT_TYPE,
      default: 0,
      length: 256,
      signed: false };

  }

  if (type === 'int') {
    return {
      type: INT_TYPE,
      default: 0,
      length: 256,
      signed: true };

  }

  if (type === 'ufixed') {
    return {
      type: FIXED_TYPE,
      default: 0,
      length: 256,
      signed: false };

  }

  if (type === 'fixed') {
    return {
      type: FIXED_TYPE,
      default: 0,
      length: 256,
      signed: true };

  }

  // If no matches, return null
  return null;
}