UNPKG

@factorial-finance/blueprint-node

Version:

blueprint-node-plugin

64 lines (63 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContractError = exports.ValidationError = void 0; exports.validateAddress = validateAddress; exports.validateRequired = validateRequired; exports.validateMethod = validateMethod; exports.validateBoc = validateBoc; exports.validateStringParams = validateStringParams; exports.validateNumericParams = validateNumericParams; const core_1 = require("@ton/core"); class ValidationError extends Error { constructor(message, code = -32602, field) { super(message); this.code = code; this.field = field; this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; class ContractError extends Error { constructor(message, code = -32603) { super(message); this.code = code; this.name = 'ContractError'; } } exports.ContractError = ContractError; function validateAddress(address) { try { core_1.Address.parse(address); } catch { throw new ValidationError(`Invalid address: ${address}`, -32602, 'address'); } } function validateRequired(value, fieldName) { if (value === undefined || value === null || value === '') { throw new ValidationError(`${fieldName} is required`, -32602, fieldName); } } function validateMethod(method) { validateRequired(method, 'method'); if (typeof method !== 'string') { throw new ValidationError('method must be a string', -32602, 'method'); } } function validateBoc(boc) { validateRequired(boc, 'boc'); if (typeof boc !== 'string') { throw new ValidationError('boc must be a string', -32602, 'boc'); } // Additional BOC validation could be added here } function validateStringParams(params, fieldName) { if (typeof params !== 'object' || params === null) { throw new ValidationError(`${fieldName} must be an object`, -32602, fieldName); } } function validateNumericParams(params, fieldName) { if (typeof params !== 'object' || params === null) { throw new ValidationError(`${fieldName} must be an object`, -32602, fieldName); } }