UNPKG

2.76 kBJavaScriptView Raw
1"use strict";
2var __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}));
9var __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});
14var __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};
21Object.defineProperty(exports, "__esModule", { value: true });
22const utils = __importStar(require("./utils"));
23const common_1 = require("../common");
24const ValidationError = utils.common.errors.ValidationError;
25function createEscrowCreationTransaction(account, payment) {
26 const txJSON = {
27 TransactionType: 'EscrowCreate',
28 Account: account,
29 Destination: payment.destination,
30 Amount: common_1.xrpToDrops(payment.amount)
31 };
32 if (payment.condition != null) {
33 txJSON.Condition = payment.condition;
34 }
35 if (payment.allowCancelAfter != null) {
36 txJSON.CancelAfter = common_1.iso8601ToRippleTime(payment.allowCancelAfter);
37 }
38 if (payment.allowExecuteAfter != null) {
39 txJSON.FinishAfter = common_1.iso8601ToRippleTime(payment.allowExecuteAfter);
40 }
41 if (payment.sourceTag != null) {
42 txJSON.SourceTag = payment.sourceTag;
43 }
44 if (payment.destinationTag != null) {
45 txJSON.DestinationTag = payment.destinationTag;
46 }
47 if (payment.memos != null) {
48 txJSON.Memos = payment.memos.map(utils.convertMemo);
49 }
50 if (Boolean(payment.allowCancelAfter) &&
51 Boolean(payment.allowExecuteAfter) &&
52 txJSON.CancelAfter <= txJSON.FinishAfter) {
53 throw new ValidationError('prepareEscrowCreation: ' +
54 '"allowCancelAfter" must be after "allowExecuteAfter"');
55 }
56 return txJSON;
57}
58function prepareEscrowCreation(address, escrowCreation, instructions = {}) {
59 try {
60 common_1.validate.prepareEscrowCreation({ address, escrowCreation, instructions });
61 const txJSON = createEscrowCreationTransaction(address, escrowCreation);
62 return utils.prepareTransaction(txJSON, this, instructions);
63 }
64 catch (e) {
65 return Promise.reject(e);
66 }
67}
68exports.default = prepareEscrowCreation;
69//# sourceMappingURL=escrow-creation.js.map
\No newline at end of file