"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _react() {
  const data = _interopRequireDefault(require("react"));

  _react = function _react() {
    return data;
  };

  return data;
}

function _utils() {
  const data = require("@ddn/utils");

  _utils = function _utils() {
    return data;
  };

  return data;
}

var _crypto = _interopRequireDefault(require("../utils/crypto"));

var _config = require("../config");

var _slots = _interopRequireDefault(require("../time/slots"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function createIssuerAuditorBuy(_x, _x2, _x3, _x4) {
  return _createIssuerAuditorBuy.apply(this, arguments);
}

function _createIssuerAuditorBuy() {
  _createIssuerAuditorBuy = _asyncToGenerator(function* (received_address, amount, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_AUDITOR_BUY,
      nethash: _config.config.nethash,
      amount,
      fee: `${fee}`,
      recipientId: received_address,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerAuditorBuy: {
          address: _crypto.default.generateAddress(keys.publicKey)
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerAuditorBuy.apply(this, arguments);
}

function createIssuerApply(_x5, _x6, _x7, _x8, _x9, _x10) {
  return _createIssuerApply.apply(this, arguments);
}

function _createIssuerApply() {
  _createIssuerApply = _asyncToGenerator(function* (orgName, org_id, orgOwner, orgOwnerPhone, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_APPLY,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerApply: {
          address: _crypto.default.generateAddress(keys.publicKey),
          orgName,
          org_id,
          orgOwner,
          orgOwnerPhone
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerApply.apply(this, arguments);
}

function createIssuerUpdate(_x11, _x12, _x13, _x14, _x15, _x16) {
  return _createIssuerUpdate.apply(this, arguments);
}

function _createIssuerUpdate() {
  _createIssuerUpdate = _asyncToGenerator(function* (orgName, org_id, orgOwner, orgOwnerPhone, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_UPDATE,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerUpdate: {
          address: _crypto.default.generateAddress(keys.publicKey),
          orgName,
          org_id,
          orgOwner,
          orgOwnerPhone
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerUpdate.apply(this, arguments);
}

function createIssuerCheck(_x17, _x18, _x19, _x20, _x21, _x22, _x23, _x24) {
  return _createIssuerCheck.apply(this, arguments);
}

function _createIssuerCheck() {
  _createIssuerCheck = _asyncToGenerator(function* (address, orgName, org_id, orgOwner, orgOwnerPhone, state, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_CHECK,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerCheck: {
          address,
          orgName,
          org_id,
          orgOwner,
          orgOwnerPhone,
          state
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerCheck.apply(this, arguments);
}

function createIssuerFreeze(_x25, _x26, _x27, _x28, _x29, _x30, _x31) {
  return _createIssuerFreeze.apply(this, arguments);
}

function _createIssuerFreeze() {
  _createIssuerFreeze = _asyncToGenerator(function* (address, orgName, org_id, orgOwner, orgOwnerPhone, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_FREEZE,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerFreeze: {
          address,
          orgName,
          org_id,
          orgOwner,
          orgOwnerPhone
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerFreeze.apply(this, arguments);
}

function createIssuerUnfreeze(_x32, _x33, _x34, _x35, _x36, _x37, _x38, _x39) {
  return _createIssuerUnfreeze.apply(this, arguments);
}

function _createIssuerUnfreeze() {
  _createIssuerUnfreeze = _asyncToGenerator(function* (address, orgName, org_id, orgOwner, orgOwnerPhone, state, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUER_UNFREEZE,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssuerUnfreeze: {
          address,
          orgName,
          org_id,
          orgOwner,
          orgOwnerPhone,
          state
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssuerUnfreeze.apply(this, arguments);
}

function createIssueNew(_x40, _x41, _x42, _x43, _x44, _x45, _x46, _x47, _x48, _x49, _x50) {
  return _createIssueNew.apply(this, arguments);
}

function _createIssueNew() {
  _createIssueNew = _asyncToGenerator(function* (goodsName, goodsSpecs, goodsUnit, goodsNum, unitPrice, batchValue, issueNum, issueTime, expireTime, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUE_NEW,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssueNew: {
          address: _crypto.default.generateAddress(keys.publicKey),
          goodsName,
          goodsSpecs,
          goodsUnit,
          goodsNum,
          unitPrice,
          batchValue,
          issueNum,
          issueTime,
          expireTime
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssueNew.apply(this, arguments);
}

function createIssueClose(_x51, _x52, _x53, _x54, _x55, _x56, _x57, _x58, _x59, _x60, _x61) {
  return _createIssueClose.apply(this, arguments);
}

function _createIssueClose() {
  _createIssueClose = _asyncToGenerator(function* (goodsName, goodsSpecs, goodsUnit, goodsNum, unitPrice, batchValue, issueNum, issueTime, expireTime, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUE_CLOSE,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssueClose: {
          address: _crypto.default.generateAddress(keys.publicKey),
          goodsName,
          goodsSpecs,
          goodsUnit,
          goodsNum,
          unitPrice,
          batchValue,
          issueNum,
          issueTime,
          expireTime
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssueClose.apply(this, arguments);
}

function createIssueReopen(_x62, _x63, _x64, _x65, _x66, _x67, _x68, _x69, _x70, _x71, _x72) {
  return _createIssueReopen.apply(this, arguments);
}

function _createIssueReopen() {
  _createIssueReopen = _asyncToGenerator(function* (goodsName, goodsSpecs, goodsUnit, goodsNum, unitPrice, batchValue, issueNum, issueTime, expireTime, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_ISSUE_REOPEN,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponIssueReopen: {
          address: _crypto.default.generateAddress(keys.publicKey),
          goodsName,
          goodsSpecs,
          goodsUnit,
          goodsNum,
          unitPrice,
          batchValue,
          issueNum,
          issueTime,
          expireTime
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createIssueReopen.apply(this, arguments);
}

function createExchangeBuy(_x73, _x74, _x75, _x76, _x77, _x78) {
  return _createExchangeBuy.apply(this, arguments);
}

function _createExchangeBuy() {
  _createExchangeBuy = _asyncToGenerator(function* (batchValue, code, received_address, price, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_EXCH_BUY,
      nethash: _config.config.nethash,
      amount: price,
      fee: `${fee}`,
      recipientId: received_address,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponExcBuy: {
          batchValue,
          code,
          sender_address: _crypto.default.generateAddress(keys.publicKey),
          received_address,
          price
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createExchangeBuy.apply(this, arguments);
}

function createExchangePay(_x79, _x80, _x81, _x82, _x83) {
  return _createExchangePay.apply(this, arguments);
}

function _createExchangePay() {
  _createExchangePay = _asyncToGenerator(function* (batchValue, code, received_address, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_EXCH_PAY,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponExcPay: {
          batchValue,
          code,
          sender_address: _crypto.default.generateAddress(keys.publicKey),
          received_address,
          price: '0'
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createExchangePay.apply(this, arguments);
}

function createExchangeTransferConfirm(_x84, _x85, _x86, _x87, _x88, _x89, _x90, _x91) {
  return _createExchangeTransferConfirm.apply(this, arguments);
}

function _createExchangeTransferConfirm() {
  _createExchangeTransferConfirm = _asyncToGenerator(function* (batchValue, code, received_address, price, related_trs_id, state, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_EXCH_TRANSFER_CONFIRM,
      nethash: _config.config.nethash,
      amount: price,
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponExcTransferConfirm: {
          batchValue,
          code,
          sender_address: _crypto.default.generateAddress(keys.publicKey),
          received_address,
          price,
          related_trs_id,
          transferState: state
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createExchangeTransferConfirm.apply(this, arguments);
}

function createExchangeTransferAsk(_x92, _x93, _x94, _x95, _x96, _x97) {
  return _createExchangeTransferAsk.apply(this, arguments);
}

function _createExchangeTransferAsk() {
  _createExchangeTransferAsk = _asyncToGenerator(function* (batchValue, code, received_address, price, secret, secondSecret) {
    const keys = _crypto.default.getKeys(secret);

    const fee = _utils().bignum.multiply(_config.constants.net.fees.transfer, _config.constants.fixedPoint);

    const transaction = {
      type: _utils().assetTypes.COUPON_EXCH_TRANSFER_ASK,
      nethash: _config.config.nethash,
      amount: '0',
      fee: `${fee}`,
      recipientId: null,
      senderPublicKey: keys.publicKey,
      timestamp: _slots.default.getTime() - _config.config.clientDriftSeconds,
      asset: {
        couponExcTransferAsk: {
          batchValue,
          code,
          sender_address: _crypto.default.generateAddress(keys.publicKey),
          received_address,
          price
        }
      }
    };
    transaction.signature = yield _crypto.default.sign(transaction, keys);

    if (secondSecret) {
      const secondKeys = _crypto.default.getKeys(secondSecret);

      transaction.sign_signature = yield _crypto.default.secondSign(transaction, secondKeys);
    }

    transaction.id = yield _crypto.default.getId(transaction);
    return transaction;
  });
  return _createExchangeTransferAsk.apply(this, arguments);
}

var _default = {
  createIssuerAuditorBuy,
  createIssuerApply,
  createIssuerCheck,
  createIssuerUpdate,
  createIssuerFreeze,
  createIssuerUnfreeze,
  createIssueNew,
  createIssueClose,
  createIssueReopen,
  createExchangeBuy,
  createExchangePay,
  createExchangeTransferAsk,
  createExchangeTransferConfirm
};
exports.default = _default;