UNPKG

hyjs-test

Version:
107 lines (106 loc) 4.45 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("./config"); const types_1 = require("./types"); const api_1 = require("./api/api"); const lib_1 = require("./lib"); const utils_1 = require("./utils"); __exportStar(require("./types"), exports); class HyMatrix extends types_1.HyMatrixBase { constructor(config) { var _a, _b; super(); this._config = { ...config, debug: (_a = config === null || config === void 0 ? void 0 : config.debug) !== null && _a !== void 0 ? _a : false, accid: (_b = config === null || config === void 0 ? void 0 : config.accid) !== null && _b !== void 0 ? _b : '' }; this._apiHost = ((config === null || config === void 0 ? void 0 : config.url) != null && config.url !== undefined && config.url !== '') ? config.url : (0, config_1.getHyMatrixHost)(this._config.debug); } async info() { const result = await (0, api_1.getInfo)(this._apiHost); return result; } async getResult(msgId) { const result = await (0, api_1.getResult)(this._apiHost, msgId); return result; } async getResults(processId, limit) { const result = await (0, api_1.getResults)(this._apiHost, processId, limit); return result; } async getMessage(msgId) { const result = await (0, api_1.getMessage)(this._apiHost, msgId); return result; } async getMessageByNonce(processId, nonce) { const result = await (0, api_1.getMessageByNonce)(this._apiHost, processId, nonce); return result; } async getAssignByNonce(processId, nonce) { const result = await (0, api_1.getAssignByNonce)(this._apiHost, processId, nonce); return result; } async getAssignByMessage(msgId) { const result = await (0, api_1.getAssignByMessage)(this._apiHost, msgId); return result; } async getNodes() { const result = await (0, api_1.getNodes)(this._apiHost); return result; } async getNode(accid) { const accTemp = accid !== null && accid !== void 0 ? accid : this._config.accid; const result = await (0, api_1.getNode)(this._apiHost, accTemp); return result; } async getNodesByProcess(processId) { const result = await (0, api_1.getNodesByProcess)(this._apiHost, processId); return result; } async getProcesses(accid) { const accTemp = accid !== null && accid !== void 0 ? accid : this._config.accid; const result = await (0, api_1.getProcesses)(this._apiHost, accTemp); return result; } async balanceOf(accid) { const accTemp = accid !== null && accid !== void 0 ? accid : this._config.accid; const result = await (0, api_1.getBalanceOfByAccid)(this._apiHost, accTemp); return result; } async stakeOf(accid) { const accTemp = accid !== null && accid !== void 0 ? accid : this._config.accid; const result = await (0, api_1.getStakeOfByAccid)(this._apiHost, accTemp); return result; } async sendMessage(params) { const info = await this.info(); const defaultBaseMessage = (0, utils_1.getDefaultBase)(types_1.BaseType.TypeMessage, info); const msg = { Base: defaultBaseMessage }; const baseTags = (0, utils_1.baseToTags)(msg.Base); const msgTags = (0, utils_1.mergeTags)(baseTags, params.tags); const binary = await (0, lib_1.createAndSignItem)(this._config, { ...params, tags: msgTags }); const result = await (0, api_1.send)(this._apiHost, binary); return { id: result.id }; } } exports.default = HyMatrix;