UNPKG

test-triam-base-contract

Version:

Low level triam smart cotnract support library

66 lines (50 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendAsset = 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 sendAsset operation. * @function * @alias Operation.sendAsset * @param {object} opts * @param {string} opts.contractId - The destination contract 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 send asset. Defaults to the transaction's source account. * @returns {xdr.SendAssetOp} */ var sendAsset = exports.sendAsset = function sendAsset(opts) { // thuannd start: thuannd notes if (!_strkey.StrKey.isValidContractKey(opts.contractId)) { throw new Error("contract is invalid"); } // thuannd end if (!opts.asset) { throw new Error("Must provide an asset for a sendAsset operation"); } if (!this.isValidAmount(opts.amount)) { throw new TypeError(this.constructAmountRequirementsError('amount')); } var attributes = {}; attributes.contractId = _keypair.Keypair.fromContractKey(opts.contractId).xdrContractId(); // now, just support native asset // if (!opts.asset.isNative()) // { // throw new Error("Just support the native asset now!"); // } attributes.asset = opts.asset.toXDRObject(); attributes.amount = this._toXDRAmount(opts.amount); attributes.state = ""; attributes.errFlag = 0; var sendAsset = new _stellarXdr_generated2.default.SendAssetOp(attributes); var opAttributes = {}; opAttributes.body = _stellarXdr_generated2.default.OperationBody.sendAsset(sendAsset); this.setSourceAccount(opAttributes, opts); return new _stellarXdr_generated2.default.Operation(opAttributes); };