var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  function adopt(value) {
    return value instanceof P ? value : new P(function (resolve) {
      resolve(value);
    });
  }

  return new (P || (P = Promise))(function (resolve, reject) {
    function fulfilled(value) {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    }

    function rejected(value) {
      try {
        step(generator["throw"](value));
      } catch (e) {
        reject(e);
      }
    }

    function step(result) {
      result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
    }

    step((generator = generator.apply(thisArg, _arguments || [])).next());
  });
};

import { http } from "../../utils/http.js";
const transactionsEndpoint = 'transactions';
/**
 * Get list of all pending transactions
 *
 * @param ky   Debug Ky instance
 */

export function getAllTransactions(ky) {
  return __awaiter(this, void 0, void 0, function* () {
    const response = yield http(ky, {
      path: transactionsEndpoint,
      responseType: 'json'
    });
    return response.data.pendingTransactions;
  });
}
/**
 * Get information for specific pending transactions
 *
 * @param ky   Debug Ky instance
 * @param transactionHash Hash of the transaction
 */

export function getTransaction(ky, transactionHash) {
  return __awaiter(this, void 0, void 0, function* () {
    const response = yield http(ky, {
      path: `${transactionsEndpoint}/${transactionHash}`,
      responseType: 'json'
    });
    return response.data;
  });
}
/**
 * Rebroadcast existing transaction
 *
 * @param ky   Debug Ky instance
 * @param transactionHash Hash of the transaction
 */

export function rebroadcastTransaction(ky, transactionHash) {
  return __awaiter(this, void 0, void 0, function* () {
    const response = yield http(ky, {
      method: 'post',
      path: `${transactionsEndpoint}/${transactionHash}`,
      responseType: 'json'
    });
    return response.data.transactionHash;
  });
}
/**
 * Cancel existing transaction
 *
 * @param ky   Debug Ky instance
 * @param transactionHash Hash of the transaction
 * @param gasPrice Optional gas price
 */

export function cancelTransaction(ky, transactionHash, gasPrice) {
  return __awaiter(this, void 0, void 0, function* () {
    const response = yield http(ky, {
      method: 'delete',
      headers: {
        'gas-price': gasPrice
      },
      path: `${transactionsEndpoint}/${transactionHash}`,
      responseType: 'json'
    });
    return response.data.transactionHash;
  });
}