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.

ledger.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. var __importDefault = (this && this.__importDefault) || function (mod) {
  22. return (mod && mod.__esModule) ? mod : { "default": mod };
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.parseLedger = void 0;
  26. const _ = __importStar(require("lodash"));
  27. const common_1 = require("../../common");
  28. const transaction_1 = __importDefault(require("./transaction"));
  29. function parseTransactionWrapper(ledgerVersion, tx) {
  30. const transaction = Object.assign({}, _.omit(tx, 'metaData'), {
  31. meta: tx.metaData,
  32. ledger_index: ledgerVersion
  33. });
  34. const result = transaction_1.default(transaction, true);
  35. if (!result.outcome.ledgerVersion) {
  36. result.outcome.ledgerVersion = ledgerVersion;
  37. }
  38. return result;
  39. }
  40. function parseTransactions(transactions, ledgerVersion) {
  41. if (_.isEmpty(transactions)) {
  42. return {};
  43. }
  44. if (typeof transactions[0] === 'string') {
  45. return { transactionHashes: transactions };
  46. }
  47. return {
  48. transactions: transactions.map(_.partial(parseTransactionWrapper, ledgerVersion))
  49. };
  50. }
  51. function parseState(state) {
  52. if (_.isEmpty(state)) {
  53. return {};
  54. }
  55. if (typeof state[0] === 'string') {
  56. return { stateHashes: state };
  57. }
  58. return { rawState: JSON.stringify(state) };
  59. }
  60. function parseLedger(ledger) {
  61. const ledgerVersion = parseInt(ledger.ledger_index, 10);
  62. return common_1.removeUndefined(Object.assign({
  63. stateHash: ledger.account_hash,
  64. closeTime: common_1.rippleTimeToISO8601(ledger.close_time),
  65. closeTimeResolution: ledger.close_time_resolution,
  66. closeFlags: ledger.close_flags,
  67. ledgerHash: ledger.ledger_hash,
  68. ledgerVersion: ledgerVersion,
  69. parentLedgerHash: ledger.parent_hash,
  70. parentCloseTime: common_1.rippleTimeToISO8601(ledger.parent_close_time),
  71. totalDrops: ledger.total_coins,
  72. transactionHash: ledger.transaction_hash
  73. }, parseTransactions(ledger.transactions, ledgerVersion), parseState(ledger.accountState)));
  74. }
  75. exports.parseLedger = parseLedger;
  76. //# sourceMappingURL=ledger.js.map