UNPKG

test-triam-base-contract

Version:

Low level triam smart cotnract support library

36 lines (29 loc) 968 B
import {default as xdr} from "../generated/stellar-xdr_generated"; import {Keypair} from "../keypair"; import {StrKey} from "../strkey"; import isUndefined from 'lodash/isUndefined'; import isString from 'lodash/isString'; /** * Create a invoke operation. * @function * @alias ContrOperation.invoke * @param {object} opts * @param {string} opts.newState - new state. * @returns {xdr.Invoke} */ export const invoke = function(opts) { let attributes = {}; if (!isString(opts.newState) && !Buffer.isBuffer(opts.newState) && opts.newState !== null) { throw new Error("newState must be a string, Buffer or null"); } if (isString(opts.newState)) { opts.newState = Buffer.from(opts.newState); } attributes.newState = opts.newState; let invoke = new xdr.Invoke(attributes); let opAttributes = {}; opAttributes.body = xdr.ContrOperationBody.invoke(invoke); return new xdr.ContrOperation(opAttributes); };