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

42 lines 1.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.pathPaymentStrictSend = void 0; const xdr_1 = __importDefault(require("../xdr")); const decode_encode_muxed_account_1 = require("../util/decode_encode_muxed_account"); function pathPaymentStrictSend(opts) { switch (true) { case !opts.sendAsset: throw new Error('Must specify a send asset'); case !this.isValidAmount(opts.sendAmount): throw new TypeError(this.constructAmountRequirementsError('sendAmount')); case !opts.destAsset: throw new Error('Must provide a destAsset for a payment operation'); case !this.isValidAmount(opts.destMin): throw new TypeError(this.constructAmountRequirementsError('destMin')); default: break; } const attributes = {}; attributes.sendAsset = opts.sendAsset.toXDRObject(); attributes.sendAmount = this._toXDRAmount(opts.sendAmount); try { attributes.destination = (0, decode_encode_muxed_account_1.decodeAddressToMuxedAccount)(opts.destination); } catch (e) { throw new Error('destination is invalid'); } attributes.destAsset = opts.destAsset.toXDRObject(); attributes.destMin = this._toXDRAmount(opts.destMin); const path = opts.path ? opts.path : []; attributes.path = path.map((x) => x.toXDRObject()); const payment = new xdr_1.default.PathPaymentStrictSendOp(attributes); const opAttributes = {}; opAttributes.body = xdr_1.default.OperationBody.pathPaymentStrictSend(payment); this.setSourceAccount(opAttributes, opts); return new xdr_1.default.Operation(opAttributes); } exports.pathPaymentStrictSend = pathPaymentStrictSend; //# sourceMappingURL=path_payment_strict_send.js.map