UNPKG

test-triam-base-contract

Version:

Low level triam smart cotnract support library

35 lines (30 loc) 1.1 kB
import {default as xdr} from "../generated/stellar-xdr_generated"; import {Keypair} from "../keypair"; import {StrKey} from "../strkey"; /** * 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} */ export const check = function(opts) { if (!StrKey.isValidEd25519PublicKey(opts.sourceAccId)) { throw new Error("destination is invalid"); } if (!this.isValidAmount(opts.amount)) { throw new TypeError(this.constructAmountRequirementsError('amount')); } let attributes = {}; attributes.sourceAccId = Keypair.fromPublicKey(opts.sourceAccId).xdrAccountId(); attributes.op = opts.op; attributes.amount = this._toXDRAmount(opts.amount); let check = new xdr.Check(attributes); let opAttributes = {}; opAttributes.body = xdr.ContrOperationBody.check(check); return new xdr.ContrOperation(opAttributes); };