{"size": 1472, "ext": "js", "max_stars_repo_path": "node_modules/minter-js-sdk/dist/cjs/api/post-signed-tx.js", "max_stars_repo_name": "Swafox/Minter-Treasurer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/minter-js-sdk/dist/cjs/api/post-signed-tx.js", "max_issues_repo_name": "Swafox/Minter-Treasurer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/minter-js-sdk/dist/cjs/api/post-signed-tx.js", "max_forks_repo_name": "Swafox/Minter-Treasurer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7735849057, "max_line_length": 149, "alphanum_fraction": 0.6610054348}
'use strict';

/**
 * @param {MinterApiInstance} apiInstance
 * @return {Function<Promise>}
 */
function PostSignedTx(apiInstance) {
  /**
   * @param {string|Buffer} signedTx
   * @param {import('axios').AxiosRequestConfig} [axiosOptions]
   * @return {Promise<NodeTransaction|{hash: string}>}
   */
  return function postSignedTx(signedTx, axiosOptions) {
    if (Buffer.isBuffer(signedTx)) {
      signedTx = "0x".concat(signedTx.toString('hex'));
    }

    return apiInstance.post('send_transaction', {
      tx: signedTx
    }, axiosOptions).then(function (response) {
      var _resData$transaction;

      var resData = response.data;

      if (((_resData$transaction = resData.transaction) === null || _resData$transaction === void 0 ? void 0 : _resData$transaction.code) > 0) {
        throw new Error("Transaction included in the block with error code ".concat(resData.transaction.code, ": ").concat(resData.transaction.log));
      } // @TODO check error code


      return resData.transaction || {
        hash: resData.hash
      };
    });
  };
}
/**
 * @typedef NodeTransaction
 * @property {string} hash
 * @property {string} raw_tx
 * @property {string} height
 * @property {string} from
 * @property {string} nonce
 * @property {string} gas
 * @property {number} gas_price
 * @property {string} gas_coin
 * @property {number} type
 * @property {TxData} data
 * @property {string} payload
 * @property {Object} tags
 */

module.exports = PostSignedTx;
