UNPKG

test-triam-base-contract

Version:

Low level triam smart cotnract support library

35 lines (28 loc) 915 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 query operation. * @function * @alias ContrOperation.query * @param {object} opts * @param {string} opts.data - query data. * @returns {xdr.Query} */ export const query = function(opts) { let attributes = {}; if (!isString(opts.data) && !Buffer.isBuffer(opts.data) && opts.data !== null) { throw new Error("data must be a string, Buffer or null"); } if (isString(opts.data)) { opts.data = Buffer.from(opts.data); } attributes.data = opts.data; let query = new xdr.Query(attributes); let opAttributes = {}; opAttributes.body = xdr.ContrOperationBody.query(query); return new xdr.ContrOperation(opAttributes); };