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.

transaction.js 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const utils_1 = require("./utils");
  7. const common_1 = require("../../common");
  8. const settings_1 = __importDefault(require("./settings"));
  9. const account_delete_1 = __importDefault(require("./account-delete"));
  10. const check_cancel_1 = __importDefault(require("./check-cancel"));
  11. const check_cash_1 = __importDefault(require("./check-cash"));
  12. const check_create_1 = __importDefault(require("./check-create"));
  13. const deposit_preauth_1 = __importDefault(require("./deposit-preauth"));
  14. const escrow_cancellation_1 = __importDefault(require("./escrow-cancellation"));
  15. const escrow_creation_1 = __importDefault(require("./escrow-creation"));
  16. const escrow_execution_1 = __importDefault(require("./escrow-execution"));
  17. const cancellation_1 = __importDefault(require("./cancellation"));
  18. const order_1 = __importDefault(require("./order"));
  19. const payment_1 = __importDefault(require("./payment"));
  20. const payment_channel_claim_1 = __importDefault(require("./payment-channel-claim"));
  21. const payment_channel_create_1 = __importDefault(require("./payment-channel-create"));
  22. const payment_channel_fund_1 = __importDefault(require("./payment-channel-fund"));
  23. const ticket_create_1 = __importDefault(require("./ticket-create"));
  24. const trustline_1 = __importDefault(require("./trustline"));
  25. const amendment_1 = __importDefault(require("./amendment"));
  26. const fee_update_1 = __importDefault(require("./fee-update"));
  27. function parseTransactionType(type) {
  28. const mapping = {
  29. AccountSet: 'settings',
  30. AccountDelete: 'accountDelete',
  31. CheckCancel: 'checkCancel',
  32. CheckCash: 'checkCash',
  33. CheckCreate: 'checkCreate',
  34. DepositPreauth: 'depositPreauth',
  35. EscrowCancel: 'escrowCancellation',
  36. EscrowCreate: 'escrowCreation',
  37. EscrowFinish: 'escrowExecution',
  38. OfferCancel: 'orderCancellation',
  39. OfferCreate: 'order',
  40. Payment: 'payment',
  41. PaymentChannelClaim: 'paymentChannelClaim',
  42. PaymentChannelCreate: 'paymentChannelCreate',
  43. PaymentChannelFund: 'paymentChannelFund',
  44. SetRegularKey: 'settings',
  45. SignerListSet: 'settings',
  46. TicketCreate: 'ticketCreate',
  47. TrustSet: 'trustline',
  48. EnableAmendment: 'amendment',
  49. SetFee: 'feeUpdate'
  50. };
  51. return mapping[type] || null;
  52. }
  53. function parseTransaction(tx, includeRawTransaction) {
  54. const type = parseTransactionType(tx.TransactionType);
  55. const mapping = {
  56. settings: settings_1.default,
  57. accountDelete: account_delete_1.default,
  58. checkCancel: check_cancel_1.default,
  59. checkCash: check_cash_1.default,
  60. checkCreate: check_create_1.default,
  61. depositPreauth: deposit_preauth_1.default,
  62. escrowCancellation: escrow_cancellation_1.default,
  63. escrowCreation: escrow_creation_1.default,
  64. escrowExecution: escrow_execution_1.default,
  65. orderCancellation: cancellation_1.default,
  66. order: order_1.default,
  67. payment: payment_1.default,
  68. paymentChannelClaim: payment_channel_claim_1.default,
  69. paymentChannelCreate: payment_channel_create_1.default,
  70. paymentChannelFund: payment_channel_fund_1.default,
  71. ticketCreate: ticket_create_1.default,
  72. trustline: trustline_1.default,
  73. amendment: amendment_1.default,
  74. feeUpdate: fee_update_1.default
  75. };
  76. const parser = mapping[type];
  77. const specification = parser
  78. ? parser(tx)
  79. : {
  80. UNAVAILABLE: 'Unrecognized transaction type.',
  81. SEE_RAW_TRANSACTION: 'Since this type is unrecognized, `rawTransaction` is included in this response.'
  82. };
  83. if (!parser) {
  84. includeRawTransaction = true;
  85. }
  86. const outcome = utils_1.parseOutcome(tx);
  87. return common_1.removeUndefined({
  88. type: type,
  89. address: tx.Account,
  90. sequence: tx.Sequence,
  91. id: tx.hash,
  92. specification: common_1.removeUndefined(specification),
  93. outcome: outcome ? common_1.removeUndefined(outcome) : undefined,
  94. rawTransaction: includeRawTransaction ? JSON.stringify(tx) : undefined
  95. });
  96. }
  97. exports.default = parseTransaction;
  98. //# sourceMappingURL=transaction.js.map