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-channel-claim.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 ValidationError = utils.common.errors.ValidationError;
  24. const claimFlags = utils.common.txFlags.PaymentChannelClaim;
  25. const common_1 = require("../common");
  26. function createPaymentChannelClaimTransaction(account, claim) {
  27. const txJSON = {
  28. Account: account,
  29. TransactionType: 'PaymentChannelClaim',
  30. Channel: claim.channel,
  31. Flags: 0
  32. };
  33. if (claim.balance != null) {
  34. txJSON.Balance = common_1.xrpToDrops(claim.balance);
  35. }
  36. if (claim.amount != null) {
  37. txJSON.Amount = common_1.xrpToDrops(claim.amount);
  38. }
  39. if (Boolean(claim.signature) !== Boolean(claim.publicKey)) {
  40. throw new ValidationError('"signature" and "publicKey" fields on' +
  41. ' PaymentChannelClaim must only be specified together.');
  42. }
  43. if (claim.signature != null) {
  44. txJSON.Signature = claim.signature;
  45. }
  46. if (claim.publicKey != null) {
  47. txJSON.PublicKey = claim.publicKey;
  48. }
  49. if (claim.renew === true && claim.close === true) {
  50. throw new ValidationError('"renew" and "close" flags on PaymentChannelClaim' +
  51. ' are mutually exclusive');
  52. }
  53. if (claim.renew === true) {
  54. txJSON.Flags |= claimFlags.Renew;
  55. }
  56. if (claim.close === true) {
  57. txJSON.Flags |= claimFlags.Close;
  58. }
  59. return txJSON;
  60. }
  61. function preparePaymentChannelClaim(address, paymentChannelClaim, instructions = {}) {
  62. try {
  63. common_1.validate.preparePaymentChannelClaim({
  64. address,
  65. paymentChannelClaim,
  66. instructions
  67. });
  68. const txJSON = createPaymentChannelClaimTransaction(address, paymentChannelClaim);
  69. return utils.prepareTransaction(txJSON, this, instructions);
  70. }
  71. catch (e) {
  72. return Promise.reject(e);
  73. }
  74. }
  75. exports.default = preparePaymentChannelClaim;
  76. //# sourceMappingURL=payment-channel-claim.js.map