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 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | const utils = __importStar(require("./utils"));
|
23 | const offerFlags = utils.common.txFlags.OfferCreate;
|
24 | const common_1 = require("../common");
|
25 | function createOrderTransaction(account, order) {
|
26 | const takerPays = common_1.toRippledAmount(order.direction === 'buy' ? order.quantity : order.totalPrice);
|
27 | const takerGets = common_1.toRippledAmount(order.direction === 'buy' ? order.totalPrice : order.quantity);
|
28 | const txJSON = {
|
29 | TransactionType: 'OfferCreate',
|
30 | Account: account,
|
31 | TakerGets: takerGets,
|
32 | TakerPays: takerPays,
|
33 | Flags: 0
|
34 | };
|
35 | if (order.direction === 'sell') {
|
36 | txJSON.Flags |= offerFlags.Sell;
|
37 | }
|
38 | if (order.passive === true) {
|
39 | txJSON.Flags |= offerFlags.Passive;
|
40 | }
|
41 | if (order.immediateOrCancel === true) {
|
42 | txJSON.Flags |= offerFlags.ImmediateOrCancel;
|
43 | }
|
44 | if (order.fillOrKill === true) {
|
45 | txJSON.Flags |= offerFlags.FillOrKill;
|
46 | }
|
47 | if (order.expirationTime != null) {
|
48 | txJSON.Expiration = common_1.iso8601ToRippleTime(order.expirationTime);
|
49 | }
|
50 | if (order.orderToReplace != null) {
|
51 | txJSON.OfferSequence = order.orderToReplace;
|
52 | }
|
53 | if (order.memos != null) {
|
54 | txJSON.Memos = order.memos.map(utils.convertMemo);
|
55 | }
|
56 | return txJSON;
|
57 | }
|
58 | function prepareOrder(address, order, instructions = {}) {
|
59 | try {
|
60 | common_1.validate.prepareOrder({ address, order, instructions });
|
61 | const txJSON = createOrderTransaction(address, order);
|
62 | return utils.prepareTransaction(txJSON, this, instructions);
|
63 | }
|
64 | catch (e) {
|
65 | return Promise.reject(e);
|
66 | }
|
67 | }
|
68 | exports.default = prepareOrder;
|
69 |
|
\ | No newline at end of file |