@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.95 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pathPaymentStrictReceive = void 0;
const xdr_1 = __importDefault(require("../xdr"));
const decode_encode_muxed_account_1 = require("../util/decode_encode_muxed_account");
function pathPaymentStrictReceive(opts) {
switch (true) {
case !opts.sendAsset:
throw new Error('Must specify a send asset');
case !this.isValidAmount(opts.sendMax):
throw new TypeError(this.constructAmountRequirementsError('sendMax'));
case !opts.destAsset:
throw new Error('Must provide a destAsset for a payment operation');
case !this.isValidAmount(opts.destAmount):
throw new TypeError(this.constructAmountRequirementsError('destAmount'));
default:
break;
}
const attributes = {};
attributes.sendAsset = opts.sendAsset.toXDRObject();
attributes.sendMax = this._toXDRAmount(opts.sendMax);
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.destAmount = this._toXDRAmount(opts.destAmount);
const path = opts.path ? opts.path : [];
attributes.path = path.map((x) => x.toXDRObject());
const payment = new xdr_1.default.PathPaymentStrictReceiveOp(attributes);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.pathPaymentStrictReceive(payment);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.pathPaymentStrictReceive = pathPaymentStrictReceive;
//# sourceMappingURL=path_payment_strict_receive.js.map