stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
141 lines (140 loc) • 5.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultRpcHandler = void 0;
const tslib_1 = require("tslib");
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const errors_1 = require("../../../stellar-plus/rpc/default-handler/errors");
class DefaultRpcHandler {
/**
*
* @param {NetworkConfig} networkConfig - The network to use.
*
* @description - The default rpc handler is used for interacting with the Soroban server.
* It uses the URL provided by the network to connect to the Soroban server and carry out the RPC functions.
*
*/
constructor(networkConfig) {
this.type = 'RpcHandler';
this.networkConfig = networkConfig;
if (!this.networkConfig.rpcUrl) {
throw errors_1.DRHError.missingRpcUrl();
}
const serverOpts = networkConfig.allowHttp ? { allowHttp: true } : {};
this.server = new stellar_sdk_1.rpc.Server(this.networkConfig.rpcUrl, serverOpts);
}
/**
*
* @param {string} txHash - The transaction hash to get.
*
* @returns {SorobanRpc.GetTransactionResponse} The transaction response from the Soroban server.
*
* @description - Gets the transaction from the Soroban server.
*/
getTransaction(txHash) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.server.getTransaction(txHash);
return response;
});
}
/**
*
* @param {Transaction} tx - The transaction to simulate.
*
* @returns {SorobanRpc.SimulateTransactionResponse} The transaction simulation response from the Soroban server.
*
* @description - Simulates the transaction on the Soroban server.
*/
simulateTransaction(tx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.server.simulateTransaction(tx);
return response;
});
}
/**
*
* @param {Transaction} tx - The transaction to prepare.
*
* @returns {Transaction} The prepared transaction.
*
* @description - Prepares the transaction on the Soroban server.
*/
prepareTransaction(tx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.server.prepareTransaction(tx);
return response;
});
}
/**
*
* @param {Transaction | SorobanFeeBumpTransaction} tx - The transaction to submit.
*
* @returns {SorobanRpc.SendTransactionResponse} The transaction submission response from the Soroban server.
*
* @description - Submits the transaction on the Soroban server.
*/
submitTransaction(tx) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.server.sendTransaction(tx);
return response;
});
}
/**
* @returns {Promise<SorobanRpc.GetLatestLedgerResponse>} The latest ledger response from the Soroban server.
* @description - Gets the latest ledger from the Soroban RPC server.
* */
getLatestLedger() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.server.getLatestLedger();
});
}
/**
* @returns {Promise<SorobanRpc.GetHealthResponse>} The health response from the Soroban server.
* @description - Gets the health of the Soroban RPC server.
* */
getHealth() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.server.getHealth();
});
}
/**
* @returns {Promise<SorobanRpc.GetNetworkResponse>} The network response from the Soroban server.
* @description - Gets the network of the Soroban RPC server.
* */
getNetwork() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.server.getNetwork();
});
}
/**
*
* @args {SorobanRpc.GetEventsRequest} request - The events request to get.
* @args {Api.EventFilter[]} request.filters - The filters to apply to the events.
* @args {number} request.startLedger - The start ledger to get the events from.
* @args {string} request.cursor - The cursor to get the events from.
* @args {number} request.limit - The limit of events to get.
*
*
* @returns {SorobanRpc.GetEventsResponse} The events response from the Soroban server.
*
* @description - Gets the events from the Soroban server.
*/
getEvents(request) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.server.getEvents(request);
});
}
/**
*
* @param {xdr.LedgerKey[]} keys - The keys to get the ledger entries for.
*
* @returns {SorobanRpc.GetLedgerEntriesResponse} The ledger entries response from the Soroban server.
*
* @description - Gets the ledger entries from the Soroban server.
*/
getLedgerEntries(...keys) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.server.getLedgerEntries(...keys);
});
}
}
exports.DefaultRpcHandler = DefaultRpcHandler;