biketrack-app/node_modules/@ethersphere/bee-js/dist/cjs/modules/debug/transactions.js

82 lines
3.0 KiB
JavaScript
Raw Normal View History

2022-07-11 10:27:11 +02:00
"use strict";
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cancelTransaction = exports.rebroadcastTransaction = exports.getTransaction = exports.getAllTransactions = void 0;
const http_1 = require("../../utils/http");
const transactionsEndpoint = 'transactions';
/**
* Get list of all pending transactions
*
* @param ky Debug Ky instance
*/
function getAllTransactions(ky) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, http_1.http)(ky, {
path: transactionsEndpoint,
responseType: 'json',
});
return response.data.pendingTransactions;
});
}
exports.getAllTransactions = getAllTransactions;
/**
* Get information for specific pending transactions
*
* @param ky Debug Ky instance
* @param transactionHash Hash of the transaction
*/
function getTransaction(ky, transactionHash) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, http_1.http)(ky, {
path: `${transactionsEndpoint}/${transactionHash}`,
responseType: 'json',
});
return response.data;
});
}
exports.getTransaction = getTransaction;
/**
* Rebroadcast existing transaction
*
* @param ky Debug Ky instance
* @param transactionHash Hash of the transaction
*/
function rebroadcastTransaction(ky, transactionHash) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, http_1.http)(ky, {
method: 'post',
path: `${transactionsEndpoint}/${transactionHash}`,
responseType: 'json',
});
return response.data.transactionHash;
});
}
exports.rebroadcastTransaction = rebroadcastTransaction;
/**
* Cancel existing transaction
*
* @param ky Debug Ky instance
* @param transactionHash Hash of the transaction
* @param gasPrice Optional gas price
*/
function cancelTransaction(ky, transactionHash, gasPrice) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, http_1.http)(ky, {
method: 'delete',
headers: { 'gas-price': gasPrice },
path: `${transactionsEndpoint}/${transactionHash}`,
responseType: 'json',
});
return response.data.transactionHash;
});
}
exports.cancelTransaction = cancelTransaction;