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.

trustline.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 bignumber_js_1 = __importDefault(require("bignumber.js"));
  26. const utils = __importStar(require("./utils"));
  27. const validate = utils.common.validate;
  28. const trustlineFlags = utils.common.txFlags.TrustSet;
  29. function convertQuality(quality) {
  30. return new bignumber_js_1.default(quality)
  31. .shiftedBy(9)
  32. .integerValue(bignumber_js_1.default.ROUND_DOWN)
  33. .toNumber();
  34. }
  35. function createTrustlineTransaction(account, trustline) {
  36. const limit = {
  37. currency: trustline.currency,
  38. issuer: trustline.counterparty,
  39. value: trustline.limit
  40. };
  41. const txJSON = {
  42. TransactionType: 'TrustSet',
  43. Account: account,
  44. LimitAmount: limit,
  45. Flags: 0
  46. };
  47. if (trustline.qualityIn != null) {
  48. txJSON.QualityIn = convertQuality(trustline.qualityIn);
  49. }
  50. if (trustline.qualityOut != null) {
  51. txJSON.QualityOut = convertQuality(trustline.qualityOut);
  52. }
  53. if (trustline.authorized === true) {
  54. txJSON.Flags |= trustlineFlags.SetAuth;
  55. }
  56. if (trustline.ripplingDisabled != null) {
  57. txJSON.Flags |= trustline.ripplingDisabled
  58. ? trustlineFlags.NoRipple
  59. : trustlineFlags.ClearNoRipple;
  60. }
  61. if (trustline.frozen != null) {
  62. txJSON.Flags |= trustline.frozen
  63. ? trustlineFlags.SetFreeze
  64. : trustlineFlags.ClearFreeze;
  65. }
  66. if (trustline.memos != null) {
  67. txJSON.Memos = trustline.memos.map(utils.convertMemo);
  68. }
  69. return txJSON;
  70. }
  71. function prepareTrustline(address, trustline, instructions = {}) {
  72. try {
  73. validate.prepareTrustline({ address, trustline, instructions });
  74. const txJSON = createTrustlineTransaction(address, trustline);
  75. return utils.prepareTransaction(txJSON, this, instructions);
  76. }
  77. catch (e) {
  78. return Promise.reject(e);
  79. }
  80. }
  81. exports.default = prepareTrustline;
  82. //# sourceMappingURL=trustline.js.map