UNPKG

test-triam-base-contract

Version:

Low level triam smart cotnract support library

51 lines (41 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.payment = undefined; var _stellarXdr_generated = require("../generated/stellar-xdr_generated"); var _stellarXdr_generated2 = _interopRequireDefault(_stellarXdr_generated); var _keypair = require("../keypair"); var _strkey = require("../strkey"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Create a payment operation. * @function * @alias Operation.payment * @param {object} opts * @param {string} opts.destination - The destination account ID. * @param {Asset} opts.asset - The asset to send. * @param {string} opts.amount - The amount to send. * @param {string} [opts.source] - The source account for the payment. Defaults to the transaction's source account. * @returns {xdr.PaymentOp} */ var payment = exports.payment = function payment(opts) { if (!_strkey.StrKey.isValidEd25519PublicKey(opts.destination)) { throw new Error("destination is invalid"); } 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')); } var attributes = {}; attributes.destination = _keypair.Keypair.fromPublicKey(opts.destination).xdrAccountId(); attributes.asset = opts.asset.toXDRObject(); attributes.amount = this._toXDRAmount(opts.amount); var payment = new _stellarXdr_generated2.default.PaymentOp(attributes); var opAttributes = {}; opAttributes.body = _stellarXdr_generated2.default.OperationBody.payment(payment); this.setSourceAccount(opAttributes, opts); return new _stellarXdr_generated2.default.Operation(opAttributes); };