You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serverinfo.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. exports.getFee = exports.getServerInfo = void 0;
  16. const utils_1 = require("./utils");
  17. const bignumber_js_1 = __importDefault(require("bignumber.js"));
  18. function renameKeys(object, mapping) {
  19. Object.entries(mapping).forEach(entry => {
  20. const [from, to] = entry;
  21. object[to] = object[from];
  22. delete object[from];
  23. });
  24. }
  25. function getServerInfo() {
  26. return this.request('server_info').then((response) => {
  27. const info = utils_1.convertKeysFromSnakeCaseToCamelCase(response.info);
  28. renameKeys(info, { hostid: 'hostID' });
  29. if (info.validatedLedger) {
  30. renameKeys(info.validatedLedger, {
  31. baseFeeXrp: 'baseFeeXRP',
  32. reserveBaseXrp: 'reserveBaseXRP',
  33. reserveIncXrp: 'reserveIncrementXRP',
  34. seq: 'ledgerVersion'
  35. });
  36. info.validatedLedger.baseFeeXRP = info.validatedLedger.baseFeeXRP.toString();
  37. info.validatedLedger.reserveBaseXRP = info.validatedLedger.reserveBaseXRP.toString();
  38. info.validatedLedger.reserveIncrementXRP = info.validatedLedger.reserveIncrementXRP.toString();
  39. }
  40. return info;
  41. });
  42. }
  43. exports.getServerInfo = getServerInfo;
  44. function getFee(cushion) {
  45. return __awaiter(this, void 0, void 0, function* () {
  46. if (cushion == null) {
  47. cushion = this._feeCushion;
  48. }
  49. if (cushion == null) {
  50. cushion = 1.2;
  51. }
  52. const serverInfo = (yield this.request('server_info')).info;
  53. const baseFeeXrp = new bignumber_js_1.default(serverInfo.validated_ledger.base_fee_xrp);
  54. if (serverInfo.load_factor == null) {
  55. serverInfo.load_factor = 1;
  56. }
  57. let fee = baseFeeXrp.times(serverInfo.load_factor).times(cushion);
  58. fee = bignumber_js_1.default.min(fee, this._maxFeeXRP);
  59. return new bignumber_js_1.default(fee.toFixed(6)).toString(10);
  60. });
  61. }
  62. exports.getFee = getFee;
  63. //# sourceMappingURL=serverinfo.js.map