test-triam-base-contract
Version:
Low level triam smart cotnract support library
47 lines (36 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.check = 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 check operation.
* @function
* @alias ContrOperation.check
* @param {object} opts
* @param {string} opts.sourceAccId - The destination account ID.
* @param {string} opts.op - operator.
* @param {string} opts.amount - The amount to send.
* @returns {xdr.Check}
*/
var check = exports.check = function check(opts) {
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.sourceAccId)) {
throw new Error("destination is invalid");
}
if (!this.isValidAmount(opts.amount)) {
throw new TypeError(this.constructAmountRequirementsError('amount'));
}
var attributes = {};
attributes.sourceAccId = _keypair.Keypair.fromPublicKey(opts.sourceAccId).xdrAccountId();
attributes.op = opts.op;
attributes.amount = this._toXDRAmount(opts.amount);
var check = new _stellarXdr_generated2.default.Check(attributes);
var opAttributes = {};
opAttributes.body = _stellarXdr_generated2.default.ContrOperationBody.check(check);
return new _stellarXdr_generated2.default.ContrOperation(opAttributes);
};