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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. exports.validate = void 0;
  7. const isEqual_1 = __importDefault(require("lodash/isEqual"));
  8. const omitBy_1 = __importDefault(require("lodash/omitBy"));
  9. const ripple_binary_codec_1 = require("ripple-binary-codec");
  10. const errors_1 = require("../../errors");
  11. const flags_1 = require("../utils/flags");
  12. const accountDelete_1 = require("./accountDelete");
  13. const accountSet_1 = require("./accountSet");
  14. const checkCancel_1 = require("./checkCancel");
  15. const checkCash_1 = require("./checkCash");
  16. const checkCreate_1 = require("./checkCreate");
  17. const depositPreauth_1 = require("./depositPreauth");
  18. const escrowCancel_1 = require("./escrowCancel");
  19. const escrowCreate_1 = require("./escrowCreate");
  20. const escrowFinish_1 = require("./escrowFinish");
  21. const NFTokenAcceptOffer_1 = require("./NFTokenAcceptOffer");
  22. const NFTokenBurn_1 = require("./NFTokenBurn");
  23. const NFTokenCancelOffer_1 = require("./NFTokenCancelOffer");
  24. const NFTokenCreateOffer_1 = require("./NFTokenCreateOffer");
  25. const NFTokenMint_1 = require("./NFTokenMint");
  26. const offerCancel_1 = require("./offerCancel");
  27. const offerCreate_1 = require("./offerCreate");
  28. const payment_1 = require("./payment");
  29. const paymentChannelClaim_1 = require("./paymentChannelClaim");
  30. const paymentChannelCreate_1 = require("./paymentChannelCreate");
  31. const paymentChannelFund_1 = require("./paymentChannelFund");
  32. const setRegularKey_1 = require("./setRegularKey");
  33. const signerListSet_1 = require("./signerListSet");
  34. const ticketCreate_1 = require("./ticketCreate");
  35. const trustSet_1 = require("./trustSet");
  36. function validate(transaction) {
  37. const tx = Object.assign({}, transaction);
  38. if (tx.TransactionType == null) {
  39. throw new errors_1.ValidationError('Object does not have a `TransactionType`');
  40. }
  41. if (typeof tx.TransactionType !== 'string') {
  42. throw new errors_1.ValidationError("Object's `TransactionType` is not a string");
  43. }
  44. (0, flags_1.setTransactionFlagsToNumber)(tx);
  45. switch (tx.TransactionType) {
  46. case 'AccountDelete':
  47. (0, accountDelete_1.validateAccountDelete)(tx);
  48. break;
  49. case 'AccountSet':
  50. (0, accountSet_1.validateAccountSet)(tx);
  51. break;
  52. case 'CheckCancel':
  53. (0, checkCancel_1.validateCheckCancel)(tx);
  54. break;
  55. case 'CheckCash':
  56. (0, checkCash_1.validateCheckCash)(tx);
  57. break;
  58. case 'CheckCreate':
  59. (0, checkCreate_1.validateCheckCreate)(tx);
  60. break;
  61. case 'DepositPreauth':
  62. (0, depositPreauth_1.validateDepositPreauth)(tx);
  63. break;
  64. case 'EscrowCancel':
  65. (0, escrowCancel_1.validateEscrowCancel)(tx);
  66. break;
  67. case 'EscrowCreate':
  68. (0, escrowCreate_1.validateEscrowCreate)(tx);
  69. break;
  70. case 'EscrowFinish':
  71. (0, escrowFinish_1.validateEscrowFinish)(tx);
  72. break;
  73. case 'NFTokenAcceptOffer':
  74. (0, NFTokenAcceptOffer_1.validateNFTokenAcceptOffer)(tx);
  75. break;
  76. case 'NFTokenBurn':
  77. (0, NFTokenBurn_1.validateNFTokenBurn)(tx);
  78. break;
  79. case 'NFTokenCancelOffer':
  80. (0, NFTokenCancelOffer_1.validateNFTokenCancelOffer)(tx);
  81. break;
  82. case 'NFTokenCreateOffer':
  83. (0, NFTokenCreateOffer_1.validateNFTokenCreateOffer)(tx);
  84. break;
  85. case 'NFTokenMint':
  86. (0, NFTokenMint_1.validateNFTokenMint)(tx);
  87. break;
  88. case 'OfferCancel':
  89. (0, offerCancel_1.validateOfferCancel)(tx);
  90. break;
  91. case 'OfferCreate':
  92. (0, offerCreate_1.validateOfferCreate)(tx);
  93. break;
  94. case 'Payment':
  95. (0, payment_1.validatePayment)(tx);
  96. break;
  97. case 'PaymentChannelClaim':
  98. (0, paymentChannelClaim_1.validatePaymentChannelClaim)(tx);
  99. break;
  100. case 'PaymentChannelCreate':
  101. (0, paymentChannelCreate_1.validatePaymentChannelCreate)(tx);
  102. break;
  103. case 'PaymentChannelFund':
  104. (0, paymentChannelFund_1.validatePaymentChannelFund)(tx);
  105. break;
  106. case 'SetRegularKey':
  107. (0, setRegularKey_1.validateSetRegularKey)(tx);
  108. break;
  109. case 'SignerListSet':
  110. (0, signerListSet_1.validateSignerListSet)(tx);
  111. break;
  112. case 'TicketCreate':
  113. (0, ticketCreate_1.validateTicketCreate)(tx);
  114. break;
  115. case 'TrustSet':
  116. (0, trustSet_1.validateTrustSet)(tx);
  117. break;
  118. default:
  119. throw new errors_1.ValidationError(`Invalid field TransactionType: ${tx.TransactionType}`);
  120. }
  121. if (!(0, isEqual_1.default)((0, ripple_binary_codec_1.decode)((0, ripple_binary_codec_1.encode)(tx)), (0, omitBy_1.default)(tx, (value) => value == null))) {
  122. throw new errors_1.ValidationError(`Invalid Transaction: ${tx.TransactionType}`);
  123. }
  124. }
  125. exports.validate = validate;
  126. //# sourceMappingURL=transaction.js.map