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.

order.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 assert = __importStar(require("assert"));
  26. const utils_1 = require("./utils");
  27. const utils_2 = require("./utils");
  28. const amount_1 = __importDefault(require("./amount"));
  29. const common_1 = require("../../common");
  30. const flags = common_1.txFlags.OfferCreate;
  31. function parseOrder(tx) {
  32. assert.ok(tx.TransactionType === 'OfferCreate');
  33. const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell';
  34. const takerGetsAmount = amount_1.default(tx.TakerGets);
  35. const takerPaysAmount = amount_1.default(tx.TakerPays);
  36. const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount;
  37. const totalPrice = direction === 'buy' ? takerGetsAmount : takerPaysAmount;
  38. return common_1.removeUndefined({
  39. memos: utils_2.parseMemos(tx),
  40. direction: direction,
  41. quantity: quantity,
  42. totalPrice: totalPrice,
  43. passive: (tx.Flags & flags.Passive) !== 0 || undefined,
  44. immediateOrCancel: (tx.Flags & flags.ImmediateOrCancel) !== 0 || undefined,
  45. fillOrKill: (tx.Flags & flags.FillOrKill) !== 0 || undefined,
  46. expirationTime: utils_1.parseTimestamp(tx.Expiration)
  47. });
  48. }
  49. exports.default = parseOrder;
  50. //# sourceMappingURL=order.js.map