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.

escrow-execution.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 validate = utils.common.validate;
  24. const ValidationError = utils.common.errors.ValidationError;
  25. function createEscrowExecutionTransaction(account, payment) {
  26. const txJSON = {
  27. TransactionType: 'EscrowFinish',
  28. Account: account,
  29. Owner: payment.owner,
  30. OfferSequence: payment.escrowSequence
  31. };
  32. if (Boolean(payment.condition) !== Boolean(payment.fulfillment)) {
  33. throw new ValidationError('"condition" and "fulfillment" fields on' +
  34. ' EscrowFinish must only be specified together.');
  35. }
  36. if (payment.condition != null) {
  37. txJSON.Condition = payment.condition;
  38. }
  39. if (payment.fulfillment != null) {
  40. txJSON.Fulfillment = payment.fulfillment;
  41. }
  42. if (payment.memos != null) {
  43. txJSON.Memos = payment.memos.map(utils.convertMemo);
  44. }
  45. return txJSON;
  46. }
  47. function prepareEscrowExecution(address, escrowExecution, instructions = {}) {
  48. try {
  49. validate.prepareEscrowExecution({ address, escrowExecution, instructions });
  50. const txJSON = createEscrowExecutionTransaction(address, escrowExecution);
  51. return utils.prepareTransaction(txJSON, this, instructions);
  52. }
  53. catch (e) {
  54. return Promise.reject(e);
  55. }
  56. }
  57. exports.default = prepareEscrowExecution;
  58. //# sourceMappingURL=escrow-execution.js.map