UNPKG

@substrate/api-sidecar

Version:

REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.

58 lines 2.81 kB
"use strict"; // Copyright 2017-2025 Parity Technologies (UK) Ltd. // This file is part of Substrate API Sidecar. // // Substrate API Sidecar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. Object.defineProperty(exports, "__esModule", { value: true }); exports.validateUseRcBlockMiddleware = void 0; const http_errors_1 = require("http-errors"); const apiRegistry_1 = require("../../apiRegistry"); /** * Express Middleware to validate the `useRcBlock` query parameter. * * This middleware performs the following validations: * 1. Asset Hub requirement - validates that the current API is connected to Asset Hub * 2. Relay chain availability - ensures relay chain API is available * 3. Boolean validation - ensures useRcBlock is a valid boolean string */ const validateUseRcBlockMiddleware = (req, _res, next) => { const { useRcBlock } = req.query; // If useRcBlock is not provided, continue without validation if (!useRcBlock) { return next(); } // 1. Boolean validation if (typeof useRcBlock !== 'string') { return next(new http_errors_1.BadRequest('useRcBlock must be a string')); } if (useRcBlock !== 'true' && useRcBlock !== 'false') { return next(new http_errors_1.BadRequest('useRcBlock must be either "true" or "false"')); } // Only validate Asset Hub and relay chain requirements if useRcBlock is true if (useRcBlock === 'true') { // 2. Asset Hub requirement check const assetHubInfo = apiRegistry_1.ApiPromiseRegistry.assetHubInfo; if (!assetHubInfo.isAssetHub) { return next(new http_errors_1.BadRequest('useRcBlock parameter is only supported for Asset Hub endpoints')); } // 3. Relay chain availability check const relayChainApis = apiRegistry_1.ApiPromiseRegistry.getApiByType('relay'); if (!relayChainApis || relayChainApis.length === 0) { return next(new http_errors_1.BadRequest('useRcBlock parameter requires relay chain API to be available. Please configure SAS_SUBSTRATE_MULTI_CHAIN_URL')); } } return next(); }; exports.validateUseRcBlockMiddleware = validateUseRcBlockMiddleware; //# sourceMappingURL=validateUseRcBlockMiddleware.js.map