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

32 lines 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.payment = void 0; const xdr_1 = __importDefault(require("../xdr")); const decode_encode_muxed_account_1 = require("../util/decode_encode_muxed_account"); function payment(opts) { if (!opts.asset) { throw new Error('Must provide an asset for a payment operation'); } if (!this.isValidAmount(opts.amount)) { throw new TypeError(this.constructAmountRequirementsError('amount')); } const attributes = {}; try { attributes.destination = (0, decode_encode_muxed_account_1.decodeAddressToMuxedAccount)(opts.destination); } catch (e) { throw new Error('destination is invalid'); } attributes.asset = opts.asset.toXDRObject(); attributes.amount = this._toXDRAmount(opts.amount); const paymentOp = new xdr_1.default.PaymentOp(attributes); const opAttributes = {}; opAttributes.body = xdr_1.default.OperationBody.payment(paymentOp); this.setSourceAccount(opAttributes, opts); return new xdr_1.default.Operation(opAttributes); } exports.payment = payment; //# sourceMappingURL=payment.js.map