UNPKG

@okxweb3/coin-stellar

Version:

@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers

43 lines 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.changeTrust = void 0; const js_xdr_1 = require("@stellar/js-xdr"); const bignumber_1 = __importDefault(require("../util/bignumber")); const xdr_1 = __importDefault(require("../xdr")); const asset_1 = require("../asset"); const liquidity_pool_asset_1 = require("../liquidity_pool_asset"); const MAX_INT64 = '9223372036854775807'; function changeTrust(opts) { const attributes = {}; if (opts.asset instanceof asset_1.Asset) { attributes.line = opts.asset.toChangeTrustXDRObject(); } else if (opts.asset instanceof liquidity_pool_asset_1.LiquidityPoolAsset) { attributes.line = opts.asset.toXDRObject(); } else { throw new TypeError('asset must be Asset or LiquidityPoolAsset'); } if (opts.limit !== undefined && !this.isValidAmount(opts.limit, true)) { throw new TypeError(this.constructAmountRequirementsError('limit')); } if (opts.limit) { attributes.limit = this._toXDRAmount(opts.limit); } else { attributes.limit = js_xdr_1.Hyper.fromString(new bignumber_1.default(MAX_INT64).toString()); } if (opts.source) { attributes.source = opts.source.masterKeypair; } const changeTrustOP = new xdr_1.default.ChangeTrustOp(attributes); const opAttributes = {}; opAttributes.body = xdr_1.default.OperationBody.changeTrust(changeTrustOP); this.setSourceAccount(opAttributes, opts); return new xdr_1.default.Operation(opAttributes); } exports.changeTrust = changeTrust; //# sourceMappingURL=change_trust.js.map