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.

payment.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. const _ = __importStar(require("lodash"));
  26. const assert = __importStar(require("assert"));
  27. const utils = __importStar(require("./utils"));
  28. const common_1 = require("../../common");
  29. const amount_1 = __importDefault(require("./amount"));
  30. function isNoDirectRipple(tx) {
  31. return (tx.Flags & common_1.txFlags.Payment.NoRippleDirect) !== 0;
  32. }
  33. function isQualityLimited(tx) {
  34. return (tx.Flags & common_1.txFlags.Payment.LimitQuality) !== 0;
  35. }
  36. function removeGenericCounterparty(amount, address) {
  37. return amount.counterparty === address
  38. ? _.omit(amount, 'counterparty')
  39. : amount;
  40. }
  41. function parsePayment(tx) {
  42. assert.ok(tx.TransactionType === 'Payment');
  43. const source = {
  44. address: tx.Account,
  45. maxAmount: removeGenericCounterparty(amount_1.default(tx.SendMax || tx.Amount), tx.Account),
  46. tag: tx.SourceTag
  47. };
  48. const destination = {
  49. address: tx.Destination,
  50. tag: tx.DestinationTag
  51. };
  52. return common_1.removeUndefined({
  53. source: common_1.removeUndefined(source),
  54. destination: common_1.removeUndefined(destination),
  55. memos: utils.parseMemos(tx),
  56. invoiceID: tx.InvoiceID,
  57. paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
  58. allowPartialPayment: utils.isPartialPayment(tx) || undefined,
  59. noDirectRipple: isNoDirectRipple(tx) || undefined,
  60. limitQuality: isQualityLimited(tx) || undefined
  61. });
  62. }
  63. exports.default = parsePayment;
  64. //# sourceMappingURL=payment.js.map