UNPKG

@gluneau/hive-mcp-server

Version:

An MCP server that enables AI assistants to interact with the Hive blockchain

113 lines 5.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountInfo = getAccountInfo; exports.getAccountHistory = getAccountHistory; exports.getVestingDelegations = getVestingDelegations; // Account-related tools implementation const client_1 = __importDefault(require("../config/client")); const error_1 = require("../utils/error"); const response_1 = require("../utils/response"); // Get account information function getAccountInfo(params) { return __awaiter(this, void 0, void 0, function* () { try { const accounts = yield client_1.default.database.getAccounts([params.username]); if (accounts.length === 0) { return (0, response_1.errorResponse)(`Error: Account ${params.username} not found`); } const accountData = accounts[0]; return (0, response_1.successJson)(accountData); } catch (error) { return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_account_info')); } }); } // Get account history function getAccountHistory(params) { return __awaiter(this, void 0, void 0, function* () { try { // The getAccountHistory method needs a starting point (from) parameter // We'll use -1 to get the most recent transactions const from = -1; // Convert string operation types to their numerical bitmask if provided let operation_bitmask = undefined; if (params.operation_filter && params.operation_filter.length > 0) { // For simplicity, we're skipping the bitmask transformation } const history = yield client_1.default.database.getAccountHistory(params.username, from, params.limit, operation_bitmask); if (!history || !Array.isArray(history)) { return (0, response_1.successJson)({ account: params.username, operations_count: 0, operations: [], }); } // Format the history into a structured object const formattedHistory = history .map(([index, operation]) => { const { timestamp, op, trx_id } = operation; const opType = op[0]; const opData = op[1]; // Filter operations if needed if (params.operation_filter && params.operation_filter.length > 0 && !params.operation_filter.includes(opType)) { return null; } return { index, type: opType, timestamp, transaction_id: trx_id, details: opData, }; }) .filter(Boolean); // Remove null entries (filtered out operations) return (0, response_1.successJson)({ account: params.username, operations_count: formattedHistory.length, operations: formattedHistory, }); } catch (error) { return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_account_history')); } }); } // Get vesting delegations function getVestingDelegations(params) { return __awaiter(this, void 0, void 0, function* () { try { const delegations = yield client_1.default.database.getVestingDelegations(params.username, params.from || "", params.limit); // Format the data for better readability const formattedDelegations = delegations.map(delegation => ({ delegator: delegation.delegator, delegatee: delegation.delegatee, vesting_shares: delegation.vesting_shares, min_delegation_time: delegation.min_delegation_time, })); return (0, response_1.successJson)({ account: params.username, delegations_count: formattedDelegations.length, delegations: formattedDelegations }); } catch (error) { return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_vesting_delegations')); } }); } //# sourceMappingURL=account.js.map